home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drawgfx.c < prev    next >
C/C++ Source or Header  |  2000-05-18  |  101KB  |  3,986 lines

  1. #ifndef DECLARE
  2.  
  3. #include "driver.h"
  4.  
  5.  
  6. /* LBO */
  7. #ifdef LSB_FIRST
  8. #define BL0 0
  9. #define BL1 1
  10. #define BL2 2
  11. #define BL3 3
  12. #define WL0 0
  13. #define WL1 1
  14. #else
  15. #define BL0 3
  16. #define BL1 2
  17. #define BL2 1
  18. #define BL3 0
  19. #define WL0 1
  20. #define WL1 0
  21. #endif
  22.  
  23.  
  24. UINT8 gfx_drawmode_table[256];
  25. plot_pixel_proc plot_pixel;
  26. read_pixel_proc read_pixel;
  27.  
  28. static UINT8 is_raw[TRANSPARENCY_MODES];
  29.  
  30.  
  31. #ifdef ALIGN_INTS /* GSL 980108 read/write nonaligned dword routine for ARM processor etc */
  32.  
  33. INLINE UINT32 read_dword(void *address)
  34. {
  35.     if ((long)address & 3)
  36.     {
  37. #ifdef LSB_FIRST  /* little endian version */
  38.           return ( *((UINT8 *)address) +
  39.                 (*((UINT8 *)address+1) << 8)  +
  40.                 (*((UINT8 *)address+2) << 16) +
  41.                 (*((UINT8 *)address+3) << 24) );
  42. #else             /* big endian version */
  43.           return ( *((UINT8 *)address+3) +
  44.                 (*((UINT8 *)address+2) << 8)  +
  45.                 (*((UINT8 *)address+1) << 16) +
  46.                 (*((UINT8 *)address)   << 24) );
  47. #endif
  48.     }
  49.     else
  50.         return *(UINT32 *)address;
  51. }
  52.  
  53.  
  54. INLINE void write_dword(void *address, UINT32 data)
  55. {
  56.       if ((long)address & 3)
  57.     {
  58. #ifdef LSB_FIRST
  59.             *((UINT8 *)address) =    data;
  60.             *((UINT8 *)address+1) = (data >> 8);
  61.             *((UINT8 *)address+2) = (data >> 16);
  62.             *((UINT8 *)address+3) = (data >> 24);
  63. #else
  64.             *((UINT8 *)address+3) =  data;
  65.             *((UINT8 *)address+2) = (data >> 8);
  66.             *((UINT8 *)address+1) = (data >> 16);
  67.             *((UINT8 *)address)   = (data >> 24);
  68. #endif
  69.         return;
  70.       }
  71.       else
  72.         *(UINT32 *)address = data;
  73. }
  74. #else
  75. #define read_dword(address) *(int *)address
  76. #define write_dword(address,data) *(int *)address=data
  77. #endif
  78.  
  79.  
  80.  
  81. INLINE int readbit(const UINT8 *src,int bitnum)
  82. {
  83.     return (src[bitnum / 8] >> (7 - bitnum % 8)) & 1;
  84. }
  85.  
  86.  
  87. void decodechar(struct GfxElement *gfx,int num,const UINT8 *src,const struct GfxLayout *gl)
  88. {
  89.     int plane,x,y;
  90.     UINT8 *dp;
  91.     int offs;
  92.  
  93.  
  94.     offs = num * gl->charincrement;
  95.     dp = gfx->gfxdata + num * gfx->char_modulo;
  96.     for (y = 0;y < gfx->height;y++)
  97.     {
  98.         int yoffs;
  99.  
  100.         yoffs = y;
  101. #ifdef PREROTATE_GFX
  102.         if (Machine->orientation & ORIENTATION_FLIP_Y)
  103.             yoffs = gfx->height-1 - yoffs;
  104. #endif
  105.  
  106.         for (x = 0;x < gfx->width;x++)
  107.         {
  108.             int xoffs;
  109.  
  110.             xoffs = x;
  111. #ifdef PREROTATE_GFX
  112.             if (Machine->orientation & ORIENTATION_FLIP_X)
  113.                 xoffs = gfx->width-1 - xoffs;
  114. #endif
  115.  
  116.             dp[x] = 0;
  117.             if (Machine->orientation & ORIENTATION_SWAP_XY)
  118.             {
  119.                 for (plane = 0;plane < gl->planes;plane++)
  120.                 {
  121.                     if (readbit(src,offs + gl->planeoffset[plane] + gl->yoffset[xoffs] + gl->xoffset[yoffs]))
  122.                         dp[x] |= (1 << (gl->planes-1-plane));
  123.                 }
  124.             }
  125.             else
  126.             {
  127.                 for (plane = 0;plane < gl->planes;plane++)
  128.                 {
  129.                     if (readbit(src,offs + gl->planeoffset[plane] + gl->yoffset[yoffs] + gl->xoffset[xoffs]))
  130.                         dp[x] |= (1 << (gl->planes-1-plane));
  131.                 }
  132.             }
  133.         }
  134.         dp += gfx->line_modulo;
  135.     }
  136.  
  137.  
  138.     if (gfx->pen_usage)
  139.     {
  140.         /* fill the pen_usage array with info on the used pens */
  141.         gfx->pen_usage[num] = 0;
  142.  
  143.         dp = gfx->gfxdata + num * gfx->char_modulo;
  144.         for (y = 0;y < gfx->height;y++)
  145.         {
  146.             for (x = 0;x < gfx->width;x++)
  147.             {
  148.                 gfx->pen_usage[num] |= 1 << dp[x];
  149.             }
  150.             dp += gfx->line_modulo;
  151.         }
  152.     }
  153. }
  154.  
  155.  
  156. struct GfxElement *decodegfx(const UINT8 *src,const struct GfxLayout *gl)
  157. {
  158.     int c;
  159.     struct GfxElement *gfx;
  160.  
  161.  
  162.     if ((gfx = malloc(sizeof(struct GfxElement))) == 0)
  163.         return 0;
  164.     memset(gfx,0,sizeof(struct GfxElement));
  165.  
  166.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  167.     {
  168.         gfx->width = gl->height;
  169.         gfx->height = gl->width;
  170.     }
  171.     else
  172.     {
  173.         gfx->width = gl->width;
  174.         gfx->height = gl->height;
  175.     }
  176.  
  177.     gfx->line_modulo = gfx->width;
  178.     gfx->char_modulo = gfx->line_modulo * gfx->height;
  179.     if ((gfx->gfxdata = malloc(gl->total * gfx->char_modulo * sizeof(UINT8))) == 0)
  180.     {
  181.         free(gfx);
  182.         return 0;
  183.     }
  184.  
  185.     gfx->total_elements = gl->total;
  186.     gfx->color_granularity = 1 << gl->planes;
  187.  
  188.     gfx->pen_usage = 0; /* need to make sure this is NULL if the next test fails) */
  189.     if (gfx->color_granularity <= 32)    /* can't handle more than 32 pens */
  190.         gfx->pen_usage = malloc(gfx->total_elements * sizeof(int));
  191.         /* no need to check for failure, the code can work without pen_usage */
  192.  
  193.     for (c = 0;c < gl->total;c++)
  194.         decodechar(gfx,c,src,gl);
  195.  
  196.     return gfx;
  197. }
  198.  
  199.  
  200. void freegfx(struct GfxElement *gfx)
  201. {
  202.     if (gfx)
  203.     {
  204.         free(gfx->pen_usage);
  205.         free(gfx->gfxdata);
  206.         free(gfx);
  207.     }
  208. }
  209.  
  210.  
  211.  
  212.  
  213. INLINE void blockmove_NtoN_transpen_noremap8(
  214.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  215.         UINT8 *dstdata,int dstmodulo,
  216.         int transpen)
  217. {
  218.     UINT8 *end;
  219.     int trans4;
  220.     UINT32 *sd4;
  221.  
  222.     srcmodulo -= srcwidth;
  223.     dstmodulo -= srcwidth;
  224.  
  225.     trans4 = transpen * 0x01010101;
  226.  
  227.     while (srcheight)
  228.     {
  229.         end = dstdata + srcwidth;
  230.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  231.         {
  232.             int col;
  233.  
  234.             col = *(srcdata++);
  235.             if (col != transpen) *dstdata = col;
  236.             dstdata++;
  237.         }
  238.         sd4 = (UINT32 *)srcdata;
  239.         while (dstdata <= end - 4)
  240.         {
  241.             UINT32 col4;
  242.  
  243.             if ((col4 = *(sd4++)) != trans4)
  244.             {
  245.                 UINT32 xod4;
  246.  
  247.                 xod4 = col4 ^ trans4;
  248.                 if( (xod4&0x000000ff) && (xod4&0x0000ff00) &&
  249.                     (xod4&0x00ff0000) && (xod4&0xff000000) )
  250.                 {
  251.                     write_dword((UINT32 *)dstdata,col4);
  252.                 }
  253.                 else
  254.                 {
  255.                     if (xod4 & 0xff000000) dstdata[BL3] = col4 >> 24;
  256.                     if (xod4 & 0x00ff0000) dstdata[BL2] = col4 >> 16;
  257.                     if (xod4 & 0x0000ff00) dstdata[BL1] = col4 >>  8;
  258.                     if (xod4 & 0x000000ff) dstdata[BL0] = col4;
  259.                 }
  260.             }
  261.             dstdata += 4;
  262.         }
  263.         srcdata = (UINT8 *)sd4;
  264.         while (dstdata < end)
  265.         {
  266.             int col;
  267.  
  268.             col = *(srcdata++);
  269.             if (col != transpen) *dstdata = col;
  270.             dstdata++;
  271.         }
  272.  
  273.         srcdata += srcmodulo;
  274.         dstdata += dstmodulo;
  275.         srcheight--;
  276.     }
  277. }
  278.  
  279. INLINE void blockmove_NtoN_transpen_noremap_flipx8(
  280.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  281.         UINT8 *dstdata,int dstmodulo,
  282.         int transpen)
  283. {
  284.     UINT8 *end;
  285.     int trans4;
  286.     UINT32 *sd4;
  287.  
  288.     srcmodulo += srcwidth;
  289.     dstmodulo -= srcwidth;
  290.     //srcdata += srcwidth-1;
  291.     srcdata -= 3;
  292.  
  293.     trans4 = transpen * 0x01010101;
  294.  
  295.     while (srcheight)
  296.     {
  297.         end = dstdata + srcwidth;
  298.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  299.         {
  300.             int col;
  301.  
  302.             col = srcdata[3];
  303.             srcdata--;
  304.             if (col != transpen) *dstdata = col;
  305.             dstdata++;
  306.         }
  307.         sd4 = (UINT32 *)srcdata;
  308.         while (dstdata <= end - 4)
  309.         {
  310.             UINT32 col4;
  311.  
  312.             if ((col4 = *(sd4--)) != trans4)
  313.             {
  314.                 UINT32 xod4;
  315.  
  316.                 xod4 = col4 ^ trans4;
  317.                 if (xod4 & 0x000000ff) dstdata[BL3] = col4;
  318.                 if (xod4 & 0x0000ff00) dstdata[BL2] = col4 >>  8;
  319.                 if (xod4 & 0x00ff0000) dstdata[BL1] = col4 >> 16;
  320.                 if (xod4 & 0xff000000) dstdata[BL0] = col4 >> 24;
  321.             }
  322.             dstdata += 4;
  323.         }
  324.         srcdata = (UINT8 *)sd4;
  325.         while (dstdata < end)
  326.         {
  327.             int col;
  328.  
  329.             col = srcdata[3];
  330.             srcdata--;
  331.             if (col != transpen) *dstdata = col;
  332.             dstdata++;
  333.         }
  334.  
  335.         srcdata += srcmodulo;
  336.         dstdata += dstmodulo;
  337.         srcheight--;
  338.     }
  339. }
  340.  
  341.  
  342. INLINE void blockmove_NtoN_transpen_noremap16(
  343.         const UINT16 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  344.         UINT16 *dstdata,int dstmodulo,
  345.         int transpen)
  346. {
  347.     UINT16 *end;
  348.  
  349.     srcmodulo -= srcwidth;
  350.     dstmodulo -= srcwidth;
  351.  
  352.     while (srcheight)
  353.     {
  354.         end = dstdata + srcwidth;
  355.         while (dstdata < end)
  356.         {
  357.             int col;
  358.  
  359.             col = *(srcdata++);
  360.             if (col != transpen) *dstdata = col;
  361.             dstdata++;
  362.         }
  363.  
  364.         srcdata += srcmodulo;
  365.         dstdata += dstmodulo;
  366.         srcheight--;
  367.     }
  368. }
  369.  
  370. INLINE void blockmove_NtoN_transpen_noremap_flipx16(
  371.         const UINT16 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  372.         UINT16 *dstdata,int dstmodulo,
  373.         int transpen)
  374. {
  375.     UINT16 *end;
  376.  
  377.     srcmodulo += srcwidth;
  378.     dstmodulo -= srcwidth;
  379.     //srcdata += srcwidth-1;
  380.  
  381.     while (srcheight)
  382.     {
  383.         end = dstdata + srcwidth;
  384.         while (dstdata < end)
  385.         {
  386.             int col;
  387.  
  388.             col = *(srcdata--);
  389.             if (col != transpen) *dstdata = col;
  390.             dstdata++;
  391.         }
  392.  
  393.         srcdata += srcmodulo;
  394.         dstdata += dstmodulo;
  395.         srcheight--;
  396.     }
  397. }
  398.  
  399.  
  400. #define DATA_TYPE UINT8
  401. #define DECLARE(function,args,body) INLINE void function##8 args body
  402. #define BLOCKMOVE(function,flipx,args) \
  403.     if (flipx) blockmove_##function##_flipx##8 args ; \
  404.     else blockmove_##function##8 args
  405. #include "drawgfx.c"
  406. #undef DATA_TYPE
  407. #undef DECLARE
  408. #undef BLOCKMOVE
  409.  
  410. #define DATA_TYPE UINT16
  411. #define DECLARE(function,args,body) INLINE void function##16 args body
  412. #define BLOCKMOVE(function,flipx,args) \
  413.     if (flipx) blockmove_##function##_flipx##16 args ; \
  414.     else blockmove_##function##16 args
  415. #include "drawgfx.c"
  416. #undef DATA_TYPE
  417. #undef DECLARE
  418. #undef BLOCKMOVE
  419.  
  420.  
  421. /***************************************************************************
  422.  
  423.   Draw graphic elements in the specified bitmap.
  424.  
  425.   transparency == TRANSPARENCY_NONE - no transparency.
  426.   transparency == TRANSPARENCY_PEN - bits whose _original_ value is == transparent_color
  427.                                      are transparent. This is the most common kind of
  428.                                      transparency.
  429.   transparency == TRANSPARENCY_PENS - as above, but transparent_color is a mask of
  430.                                        transparent pens.
  431.   transparency == TRANSPARENCY_COLOR - bits whose _remapped_ palette index (taken from
  432.                                      Machine->game_colortable) is == transparent_color
  433.   transparency == TRANSPARENCY_THROUGH - if the _destination_ pixel is == transparent_color,
  434.                                      the source pixel is drawn over it. This is used by
  435.                                      e.g. Jr. Pac Man to draw the sprites when the background
  436.                                      has priority over them.
  437.  
  438.   transparency == TRANSPARENCY_PEN_TABLE - the transparency condition is same as TRANSPARENCY_PEN
  439.                     A special drawing is done according to gfx_drawmode_table[source pixel].
  440.                     DRAWMODE_NONE      transparent
  441.                     DRAWMODE_SOURCE    normal, draw source pixel.
  442.                     DRAWMODE_SHADOW    destination is changed through palette_shadow_table[]
  443.                     DRAWMODE_HIGHLIGHT destination is changed through palette_highlight_table[]
  444.  
  445. ***************************************************************************/
  446.  
  447. INLINE void common_drawgfx(struct osd_bitmap *dest,const struct GfxElement *gfx,
  448.         unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
  449.         const struct rectangle *clip,int transparency,int transparent_color,
  450.         struct osd_bitmap *pri_buffer,UINT32 pri_mask)
  451. {
  452.     struct rectangle myclip;
  453.  
  454.     if (!gfx)
  455.     {
  456.         usrintf_showmessage("drawgfx() gfx == 0");
  457.         return;
  458.     }
  459.     if (!gfx->colortable && !is_raw[transparency])
  460.     {
  461.         usrintf_showmessage("drawgfx() gfx->colortable == 0");
  462.         return;
  463.     }
  464.  
  465.     code %= gfx->total_elements;
  466.     if (!is_raw[transparency])
  467.         color %= gfx->total_colors;
  468.  
  469.     if (gfx->pen_usage && (transparency == TRANSPARENCY_PEN || transparency == TRANSPARENCY_PENS))
  470.     {
  471.         int transmask = 0;
  472.  
  473.         if (transparency == TRANSPARENCY_PEN)
  474.         {
  475.             transmask = 1 << transparent_color;
  476.         }
  477.         else if (transparency == TRANSPARENCY_PENS)
  478.         {
  479.             transmask = transparent_color;
  480.         }
  481.  
  482.         if ((gfx->pen_usage[code] & ~transmask) == 0)
  483.             /* character is totally transparent, no need to draw */
  484.             return;
  485.         else if ((gfx->pen_usage[code] & transmask) == 0 && transparency != TRANSPARENCY_THROUGH && transparency != TRANSPARENCY_PEN_TABLE )
  486.             /* character is totally opaque, can disable transparency */
  487.             transparency = TRANSPARENCY_NONE;
  488.     }
  489.  
  490.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  491.     {
  492.         int temp;
  493.  
  494.         temp = sx;
  495.         sx = sy;
  496.         sy = temp;
  497.  
  498.         temp = flipx;
  499.         flipx = flipy;
  500.         flipy = temp;
  501.  
  502.         if (clip)
  503.         {
  504.             /* clip and myclip might be the same, so we need a temporary storage */
  505.             temp = clip->min_x;
  506.             myclip.min_x = clip->min_y;
  507.             myclip.min_y = temp;
  508.             temp = clip->max_x;
  509.             myclip.max_x = clip->max_y;
  510.             myclip.max_y = temp;
  511.             clip = &myclip;
  512.         }
  513.     }
  514.     if (Machine->orientation & ORIENTATION_FLIP_X)
  515.     {
  516.         sx = dest->width - gfx->width - sx;
  517.         if (clip)
  518.         {
  519.             int temp;
  520.  
  521.  
  522.             /* clip and myclip might be the same, so we need a temporary storage */
  523.             temp = clip->min_x;
  524.             myclip.min_x = dest->width-1 - clip->max_x;
  525.             myclip.max_x = dest->width-1 - temp;
  526.             myclip.min_y = clip->min_y;
  527.             myclip.max_y = clip->max_y;
  528.             clip = &myclip;
  529.         }
  530. #ifndef PREROTATE_GFX
  531.         flipx = !flipx;
  532. #endif
  533.     }
  534.     if (Machine->orientation & ORIENTATION_FLIP_Y)
  535.     {
  536.         sy = dest->height - gfx->height - sy;
  537.         if (clip)
  538.         {
  539.             int temp;
  540.  
  541.  
  542.             myclip.min_x = clip->min_x;
  543.             myclip.max_x = clip->max_x;
  544.             /* clip and myclip might be the same, so we need a temporary storage */
  545.             temp = clip->min_y;
  546.             myclip.min_y = dest->height-1 - clip->max_y;
  547.             myclip.max_y = dest->height-1 - temp;
  548.             clip = &myclip;
  549.         }
  550. #ifndef PREROTATE_GFX
  551.         flipy = !flipy;
  552. #endif
  553.     }
  554.  
  555.     if (dest->depth != 16)
  556.         drawgfx_core8(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
  557.     else
  558.         drawgfx_core16(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,pri_buffer,pri_mask);
  559. }
  560.  
  561. void drawgfx(struct osd_bitmap *dest,const struct GfxElement *gfx,
  562.         unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
  563.         const struct rectangle *clip,int transparency,int transparent_color)
  564. {
  565.     common_drawgfx(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,NULL,0);
  566. }
  567.  
  568. void pdrawgfx(struct osd_bitmap *dest,const struct GfxElement *gfx,
  569.         unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
  570.         const struct rectangle *clip,int transparency,int transparent_color,UINT32 priority_mask)
  571. {
  572.     common_drawgfx(dest,gfx,code,color,flipx,flipy,sx,sy,clip,transparency,transparent_color,priority_bitmap,priority_mask);
  573. }
  574.  
  575.  
  576. /***************************************************************************
  577.  
  578.   Use drawgfx() to copy a bitmap onto another at the given position.
  579.   This function will very likely change in the future.
  580.  
  581. ***************************************************************************/
  582. void copybitmap(struct osd_bitmap *dest,struct osd_bitmap *src,int flipx,int flipy,int sx,int sy,
  583.         const struct rectangle *clip,int transparency,int transparent_color)
  584. {
  585.     /* translate to proper transparency here */
  586.     if (transparency == TRANSPARENCY_NONE)
  587.         transparency = TRANSPARENCY_NONE_RAW;
  588.     else if (transparency == TRANSPARENCY_PEN || transparency == TRANSPARENCY_COLOR)
  589.         transparency = TRANSPARENCY_PEN_RAW;
  590.     else if (transparency == TRANSPARENCY_THROUGH)
  591.         transparency = TRANSPARENCY_THROUGH_RAW;
  592.  
  593.     copybitmap_remap(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
  594. }
  595.  
  596.  
  597. void copybitmap_remap(struct osd_bitmap *dest,struct osd_bitmap *src,int flipx,int flipy,int sx,int sy,
  598.         const struct rectangle *clip,int transparency,int transparent_color)
  599. {
  600.     struct rectangle myclip;
  601.  
  602.  
  603.     /* if necessary, remap the transparent color */
  604.     if (transparency == TRANSPARENCY_COLOR)
  605.         transparent_color = Machine->pens[transparent_color];
  606.  
  607.  
  608.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  609.     {
  610.         int temp;
  611.  
  612.         temp = sx;
  613.         sx = sy;
  614.         sy = temp;
  615.  
  616.         temp = flipx;
  617.         flipx = flipy;
  618.         flipy = temp;
  619.  
  620.         if (clip)
  621.         {
  622.             /* clip and myclip might be the same, so we need a temporary storage */
  623.             temp = clip->min_x;
  624.             myclip.min_x = clip->min_y;
  625.             myclip.min_y = temp;
  626.             temp = clip->max_x;
  627.             myclip.max_x = clip->max_y;
  628.             myclip.max_y = temp;
  629.             clip = &myclip;
  630.         }
  631.     }
  632.     if (Machine->orientation & ORIENTATION_FLIP_X)
  633.     {
  634.         sx = dest->width - src->width - sx;
  635.         if (clip)
  636.         {
  637.             int temp;
  638.  
  639.  
  640.             /* clip and myclip might be the same, so we need a temporary storage */
  641.             temp = clip->min_x;
  642.             myclip.min_x = dest->width-1 - clip->max_x;
  643.             myclip.max_x = dest->width-1 - temp;
  644.             myclip.min_y = clip->min_y;
  645.             myclip.max_y = clip->max_y;
  646.             clip = &myclip;
  647.         }
  648.     }
  649.     if (Machine->orientation & ORIENTATION_FLIP_Y)
  650.     {
  651.         sy = dest->height - src->height - sy;
  652.         if (clip)
  653.         {
  654.             int temp;
  655.  
  656.  
  657.             myclip.min_x = clip->min_x;
  658.             myclip.max_x = clip->max_x;
  659.             /* clip and myclip might be the same, so we need a temporary storage */
  660.             temp = clip->min_y;
  661.             myclip.min_y = dest->height-1 - clip->max_y;
  662.             myclip.max_y = dest->height-1 - temp;
  663.             clip = &myclip;
  664.         }
  665.     }
  666.  
  667.     if (dest->depth != 16)
  668.         copybitmap_core8(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
  669.     else
  670.         copybitmap_core16(dest,src,flipx,flipy,sx,sy,clip,transparency,transparent_color);
  671. }
  672.  
  673.  
  674. void copybitmapzoom(struct osd_bitmap *dest_bmp,struct osd_bitmap *source_bmp,int flipx,int flipy,int sx,int sy,
  675.         const struct rectangle *clip,int transparency,int transparent_color,int scalex,int scaley)
  676. {
  677.     struct rectangle myclip;
  678.  
  679.  
  680.     /*
  681.     scalex and scaley are 16.16 fixed point numbers
  682.     1<<15 : shrink to 50%
  683.     1<<16 : uniform scale
  684.     1<<17 : double to 200%
  685.     */
  686.  
  687.     /* if necessary, remap the transparent color */
  688.     if (transparency == TRANSPARENCY_COLOR)
  689.         transparent_color = Machine->pens[transparent_color];
  690.  
  691.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  692.     {
  693.         int temp;
  694.  
  695.         temp = sx;
  696.         sx = sy;
  697.         sy = temp;
  698.  
  699.         temp = flipx;
  700.         flipx = flipy;
  701.         flipy = temp;
  702.  
  703.         temp = scalex;
  704.         scalex = scaley;
  705.         scaley = temp;
  706.  
  707.         if (clip)
  708.         {
  709.             /* clip and myclip might be the same, so we need a temporary storage */
  710.             temp = clip->min_x;
  711.             myclip.min_x = clip->min_y;
  712.             myclip.min_y = temp;
  713.             temp = clip->max_x;
  714.             myclip.max_x = clip->max_y;
  715.             myclip.max_y = temp;
  716.             clip = &myclip;
  717.         }
  718.     }
  719.     if (Machine->orientation & ORIENTATION_FLIP_X)
  720.     {
  721.         sx = dest_bmp->width - ((source_bmp->width * scalex + 0x7fff) >> 16) - sx;
  722.         if (clip)
  723.         {
  724.             int temp;
  725.  
  726.  
  727.             /* clip and myclip might be the same, so we need a temporary storage */
  728.             temp = clip->min_x;
  729.             myclip.min_x = dest_bmp->width-1 - clip->max_x;
  730.             myclip.max_x = dest_bmp->width-1 - temp;
  731.             myclip.min_y = clip->min_y;
  732.             myclip.max_y = clip->max_y;
  733.             clip = &myclip;
  734.         }
  735.     }
  736.     if (Machine->orientation & ORIENTATION_FLIP_Y)
  737.     {
  738.         sy = dest_bmp->height - ((source_bmp->height * scaley + 0x7fff) >> 16) - sy;
  739.         if (clip)
  740.         {
  741.             int temp;
  742.  
  743.  
  744.             myclip.min_x = clip->min_x;
  745.             myclip.max_x = clip->max_x;
  746.             /* clip and myclip might be the same, so we need a temporary storage */
  747.             temp = clip->min_y;
  748.             myclip.min_y = dest_bmp->height-1 - clip->max_y;
  749.             myclip.max_y = dest_bmp->height-1 - temp;
  750.             clip = &myclip;
  751.         }
  752.     }
  753.  
  754.  
  755.     /* ASG 980209 -- added 16-bit version */
  756.     if (dest_bmp->depth != 16)
  757.     {
  758.         int sprite_screen_height = (scaley*source_bmp->height+0x8000)>>16;
  759.         int sprite_screen_width = (scalex*source_bmp->width+0x8000)>>16;
  760.  
  761.         /* compute sprite increment per screen pixel */
  762.         int dx = (source_bmp->width<<16)/sprite_screen_width;
  763.         int dy = (source_bmp->height<<16)/sprite_screen_height;
  764.  
  765.         int ex = sx+sprite_screen_width;
  766.         int ey = sy+sprite_screen_height;
  767.  
  768.         int x_index_base;
  769.         int y_index;
  770.  
  771.         if( flipx )
  772.         {
  773.             x_index_base = (sprite_screen_width-1)*dx;
  774.             dx = -dx;
  775.         }
  776.         else
  777.         {
  778.             x_index_base = 0;
  779.         }
  780.  
  781.         if( flipy )
  782.         {
  783.             y_index = (sprite_screen_height-1)*dy;
  784.             dy = -dy;
  785.         }
  786.         else
  787.         {
  788.             y_index = 0;
  789.         }
  790.  
  791.         if( clip )
  792.         {
  793.             if( sx < clip->min_x)
  794.             { /* clip left */
  795.                 int pixels = clip->min_x-sx;
  796.                 sx += pixels;
  797.                 x_index_base += pixels*dx;
  798.             }
  799.             if( sy < clip->min_y )
  800.             { /* clip top */
  801.                 int pixels = clip->min_y-sy;
  802.                 sy += pixels;
  803.                 y_index += pixels*dy;
  804.             }
  805.             /* NS 980211 - fixed incorrect clipping */
  806.             if( ex > clip->max_x+1 )
  807.             { /* clip right */
  808.                 int pixels = ex-clip->max_x-1;
  809.                 ex -= pixels;
  810.             }
  811.             if( ey > clip->max_y+1 )
  812.             { /* clip bottom */
  813.                 int pixels = ey-clip->max_y-1;
  814.                 ey -= pixels;
  815.             }
  816.         }
  817.  
  818.         if( ex>sx )
  819.         { /* skip if inner loop doesn't draw anything */
  820.             int y;
  821.  
  822.             switch (transparency)
  823.             {
  824.                 case TRANSPARENCY_NONE:
  825.                     for( y=sy; y<ey; y++ )
  826.                     {
  827.                         UINT8 *source = source_bmp->line[(y_index>>16)];
  828.                         UINT8 *dest = dest_bmp->line[y];
  829.  
  830.                         int x, x_index = x_index_base;
  831.                         for( x=sx; x<ex; x++ )
  832.                         {
  833.                             dest[x] = source[x_index>>16];
  834.                             x_index += dx;
  835.                         }
  836.  
  837.                         y_index += dy;
  838.                     }
  839.                     break;
  840.  
  841.                 case TRANSPARENCY_PEN:
  842.                 case TRANSPARENCY_COLOR:
  843.                     for( y=sy; y<ey; y++ )
  844.                     {
  845.                         UINT8 *source = source_bmp->line[(y_index>>16)];
  846.                         UINT8 *dest = dest_bmp->line[y];
  847.  
  848.                         int x, x_index = x_index_base;
  849.                         for( x=sx; x<ex; x++ )
  850.                         {
  851.                             int c = source[x_index>>16];
  852.                             if( c != transparent_color ) dest[x] = c;
  853.                             x_index += dx;
  854.                         }
  855.  
  856.                         y_index += dy;
  857.                     }
  858.                     break;
  859.  
  860.                 case TRANSPARENCY_THROUGH:
  861. usrintf_showmessage("copybitmapzoom() TRANSPARENCY_THROUGH");
  862.                     break;
  863.             }
  864.         }
  865.     }
  866.  
  867.     /* ASG 980209 -- new 16-bit part */
  868.     else
  869.     {
  870.         int sprite_screen_height = (scaley*source_bmp->height+0x8000)>>16;
  871.         int sprite_screen_width = (scalex*source_bmp->width+0x8000)>>16;
  872.  
  873.         /* compute sprite increment per screen pixel */
  874.         int dx = (source_bmp->width<<16)/sprite_screen_width;
  875.         int dy = (source_bmp->height<<16)/sprite_screen_height;
  876.  
  877.         int ex = sx+sprite_screen_width;
  878.         int ey = sy+sprite_screen_height;
  879.  
  880.         int x_index_base;
  881.         int y_index;
  882.  
  883.         if( flipx )
  884.         {
  885.             x_index_base = (sprite_screen_width-1)*dx;
  886.             dx = -dx;
  887.         }
  888.         else
  889.         {
  890.             x_index_base = 0;
  891.         }
  892.  
  893.         if( flipy )
  894.         {
  895.             y_index = (sprite_screen_height-1)*dy;
  896.             dy = -dy;
  897.         }
  898.         else
  899.         {
  900.             y_index = 0;
  901.         }
  902.  
  903.         if( clip )
  904.         {
  905.             if( sx < clip->min_x)
  906.             { /* clip left */
  907.                 int pixels = clip->min_x-sx;
  908.                 sx += pixels;
  909.                 x_index_base += pixels*dx;
  910.             }
  911.             if( sy < clip->min_y )
  912.             { /* clip top */
  913.                 int pixels = clip->min_y-sy;
  914.                 sy += pixels;
  915.                 y_index += pixels*dy;
  916.             }
  917.             /* NS 980211 - fixed incorrect clipping */
  918.             if( ex > clip->max_x+1 )
  919.             { /* clip right */
  920.                 int pixels = ex-clip->max_x-1;
  921.                 ex -= pixels;
  922.             }
  923.             if( ey > clip->max_y+1 )
  924.             { /* clip bottom */
  925.                 int pixels = ey-clip->max_y-1;
  926.                 ey -= pixels;
  927.             }
  928.         }
  929.  
  930.         if( ex>sx )
  931.         { /* skip if inner loop doesn't draw anything */
  932.             int y;
  933.  
  934.             switch (transparency)
  935.             {
  936.                 case TRANSPARENCY_NONE:
  937.                     for( y=sy; y<ey; y++ )
  938.                     {
  939.                         UINT16 *source = (UINT16 *)source_bmp->line[(y_index>>16)];
  940.                         UINT16 *dest = (UINT16 *)dest_bmp->line[y];
  941.  
  942.                         int x, x_index = x_index_base;
  943.                         for( x=sx; x<ex; x++ )
  944.                         {
  945.                             dest[x] = source[x_index>>16];
  946.                             x_index += dx;
  947.                         }
  948.  
  949.                         y_index += dy;
  950.                     }
  951.                     break;
  952.  
  953.                 case TRANSPARENCY_PEN:
  954.                 case TRANSPARENCY_COLOR:
  955.                     for( y=sy; y<ey; y++ )
  956.                     {
  957.                         UINT16 *source = (UINT16 *)source_bmp->line[(y_index>>16)];
  958.                         UINT16 *dest = (UINT16 *)dest_bmp->line[y];
  959.  
  960.                         int x, x_index = x_index_base;
  961.                         for( x=sx; x<ex; x++ )
  962.                         {
  963.                             int c = source[x_index>>16];
  964.                             if( c != transparent_color ) dest[x] = c;
  965.                             x_index += dx;
  966.                         }
  967.  
  968.                         y_index += dy;
  969.                     }
  970.                     break;
  971.  
  972.                 case TRANSPARENCY_THROUGH:
  973. usrintf_showmessage("copybitmapzoom() TRANSPARENCY_THROUGH");
  974.                     break;
  975.             }
  976.         }
  977.     }
  978. }
  979.  
  980.  
  981. /***************************************************************************
  982.  
  983.   Copy a bitmap onto another with scroll and wraparound.
  984.   This function supports multiple independently scrolling rows/columns.
  985.   "rows" is the number of indepentently scrolling rows. "rowscroll" is an
  986.   array of integers telling how much to scroll each row. Same thing for
  987.   "cols" and "colscroll".
  988.   If the bitmap cannot scroll in one direction, set rows or columns to 0.
  989.   If the bitmap scrolls as a whole, set rows and/or cols to 1.
  990.   Bidirectional scrolling is, of course, supported only if the bitmap
  991.   scrolls as a whole in at least one direction.
  992.  
  993. ***************************************************************************/
  994. void copyscrollbitmap(struct osd_bitmap *dest,struct osd_bitmap *src,
  995.         int rows,const int *rowscroll,int cols,const int *colscroll,
  996.         const struct rectangle *clip,int transparency,int transparent_color)
  997. {
  998.     /* translate to proper transparency here */
  999.     if (transparency == TRANSPARENCY_NONE)
  1000.         transparency = TRANSPARENCY_NONE_RAW;
  1001.     else if (transparency == TRANSPARENCY_PEN || transparency == TRANSPARENCY_COLOR)
  1002.         transparency = TRANSPARENCY_PEN_RAW;
  1003.     else if (transparency == TRANSPARENCY_THROUGH)
  1004.         transparency = TRANSPARENCY_THROUGH_RAW;
  1005.  
  1006.     copyscrollbitmap_remap(dest,src,rows,rowscroll,cols,colscroll,clip,transparency,transparent_color);
  1007. }
  1008.  
  1009. void copyscrollbitmap_remap(struct osd_bitmap *dest,struct osd_bitmap *src,
  1010.         int rows,const int *rowscroll,int cols,const int *colscroll,
  1011.         const struct rectangle *clip,int transparency,int transparent_color)
  1012. {
  1013.     int srcwidth,srcheight,destwidth,destheight;
  1014.  
  1015.  
  1016.     if (rows == 0 && cols == 0)
  1017.     {
  1018.         copybitmap(dest,src,0,0,0,0,clip,transparency,transparent_color);
  1019.         return;
  1020.     }
  1021.  
  1022.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  1023.     {
  1024.         srcwidth = src->height;
  1025.         srcheight = src->width;
  1026.         destwidth = dest->height;
  1027.         destheight = dest->width;
  1028.     }
  1029.     else
  1030.     {
  1031.         srcwidth = src->width;
  1032.         srcheight = src->height;
  1033.         destwidth = dest->width;
  1034.         destheight = dest->height;
  1035.     }
  1036.  
  1037.     if (rows == 0)
  1038.     {
  1039.         /* scrolling columns */
  1040.         int col,colwidth;
  1041.         struct rectangle myclip;
  1042.  
  1043.  
  1044.         colwidth = srcwidth / cols;
  1045.  
  1046.         myclip.min_y = clip->min_y;
  1047.         myclip.max_y = clip->max_y;
  1048.  
  1049.         col = 0;
  1050.         while (col < cols)
  1051.         {
  1052.             int cons,scroll;
  1053.  
  1054.  
  1055.             /* count consecutive columns scrolled by the same amount */
  1056.             scroll = colscroll[col];
  1057.             cons = 1;
  1058.             while (col + cons < cols &&    colscroll[col + cons] == scroll)
  1059.                 cons++;
  1060.  
  1061.             if (scroll < 0) scroll = srcheight - (-scroll) % srcheight;
  1062.             else scroll %= srcheight;
  1063.  
  1064.             myclip.min_x = col * colwidth;
  1065.             if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
  1066.             myclip.max_x = (col + cons) * colwidth - 1;
  1067.             if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
  1068.  
  1069.             copybitmap(dest,src,0,0,0,scroll,&myclip,transparency,transparent_color);
  1070.             copybitmap(dest,src,0,0,0,scroll - srcheight,&myclip,transparency,transparent_color);
  1071.  
  1072.             col += cons;
  1073.         }
  1074.     }
  1075.     else if (cols == 0)
  1076.     {
  1077.         /* scrolling rows */
  1078.         int row,rowheight;
  1079.         struct rectangle myclip;
  1080.  
  1081.  
  1082.         rowheight = srcheight / rows;
  1083.  
  1084.         myclip.min_x = clip->min_x;
  1085.         myclip.max_x = clip->max_x;
  1086.  
  1087.         row = 0;
  1088.         while (row < rows)
  1089.         {
  1090.             int cons,scroll;
  1091.  
  1092.  
  1093.             /* count consecutive rows scrolled by the same amount */
  1094.             scroll = rowscroll[row];
  1095.             cons = 1;
  1096.             while (row + cons < rows &&    rowscroll[row + cons] == scroll)
  1097.                 cons++;
  1098.  
  1099.             if (scroll < 0) scroll = srcwidth - (-scroll) % srcwidth;
  1100.             else scroll %= srcwidth;
  1101.  
  1102.             myclip.min_y = row * rowheight;
  1103.             if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
  1104.             myclip.max_y = (row + cons) * rowheight - 1;
  1105.             if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
  1106.  
  1107.             copybitmap(dest,src,0,0,scroll,0,&myclip,transparency,transparent_color);
  1108.             copybitmap(dest,src,0,0,scroll - srcwidth,0,&myclip,transparency,transparent_color);
  1109.  
  1110.             row += cons;
  1111.         }
  1112.     }
  1113.     else if (rows == 1 && cols == 1)
  1114.     {
  1115.         /* XY scrolling playfield */
  1116.         int scrollx,scrolly,sx,sy;
  1117.  
  1118.  
  1119.         if (rowscroll[0] < 0) scrollx = srcwidth - (-rowscroll[0]) % srcwidth;
  1120.         else scrollx = rowscroll[0] % srcwidth;
  1121.  
  1122.         if (colscroll[0] < 0) scrolly = srcheight - (-colscroll[0]) % srcheight;
  1123.         else scrolly = colscroll[0] % srcheight;
  1124.  
  1125.         for (sx = scrollx - srcwidth;sx < destwidth;sx += srcwidth)
  1126.             for (sy = scrolly - srcheight;sy < destheight;sy += srcheight)
  1127.                 copybitmap(dest,src,0,0,sx,sy,clip,transparency,transparent_color);
  1128.     }
  1129.     else if (rows == 1)
  1130.     {
  1131.         /* scrolling columns + horizontal scroll */
  1132.         int col,colwidth;
  1133.         int scrollx;
  1134.         struct rectangle myclip;
  1135.  
  1136.  
  1137.         if (rowscroll[0] < 0) scrollx = srcwidth - (-rowscroll[0]) % srcwidth;
  1138.         else scrollx = rowscroll[0] % srcwidth;
  1139.  
  1140.         colwidth = srcwidth / cols;
  1141.  
  1142.         myclip.min_y = clip->min_y;
  1143.         myclip.max_y = clip->max_y;
  1144.  
  1145.         col = 0;
  1146.         while (col < cols)
  1147.         {
  1148.             int cons,scroll;
  1149.  
  1150.  
  1151.             /* count consecutive columns scrolled by the same amount */
  1152.             scroll = colscroll[col];
  1153.             cons = 1;
  1154.             while (col + cons < cols &&    colscroll[col + cons] == scroll)
  1155.                 cons++;
  1156.  
  1157.             if (scroll < 0) scroll = srcheight - (-scroll) % srcheight;
  1158.             else scroll %= srcheight;
  1159.  
  1160.             myclip.min_x = col * colwidth + scrollx;
  1161.             if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
  1162.             myclip.max_x = (col + cons) * colwidth - 1 + scrollx;
  1163.             if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
  1164.  
  1165.             copybitmap(dest,src,0,0,scrollx,scroll,&myclip,transparency,transparent_color);
  1166.             copybitmap(dest,src,0,0,scrollx,scroll - srcheight,&myclip,transparency,transparent_color);
  1167.  
  1168.             myclip.min_x = col * colwidth + scrollx - srcwidth;
  1169.             if (myclip.min_x < clip->min_x) myclip.min_x = clip->min_x;
  1170.             myclip.max_x = (col + cons) * colwidth - 1 + scrollx - srcwidth;
  1171.             if (myclip.max_x > clip->max_x) myclip.max_x = clip->max_x;
  1172.  
  1173.             copybitmap(dest,src,0,0,scrollx - srcwidth,scroll,&myclip,transparency,transparent_color);
  1174.             copybitmap(dest,src,0,0,scrollx - srcwidth,scroll - srcheight,&myclip,transparency,transparent_color);
  1175.  
  1176.             col += cons;
  1177.         }
  1178.     }
  1179.     else if (cols == 1)
  1180.     {
  1181.         /* scrolling rows + vertical scroll */
  1182.         int row,rowheight;
  1183.         int scrolly;
  1184.         struct rectangle myclip;
  1185.  
  1186.  
  1187.         if (colscroll[0] < 0) scrolly = srcheight - (-colscroll[0]) % srcheight;
  1188.         else scrolly = colscroll[0] % srcheight;
  1189.  
  1190.         rowheight = srcheight / rows;
  1191.  
  1192.         myclip.min_x = clip->min_x;
  1193.         myclip.max_x = clip->max_x;
  1194.  
  1195.         row = 0;
  1196.         while (row < rows)
  1197.         {
  1198.             int cons,scroll;
  1199.  
  1200.  
  1201.             /* count consecutive rows scrolled by the same amount */
  1202.             scroll = rowscroll[row];
  1203.             cons = 1;
  1204.             while (row + cons < rows &&    rowscroll[row + cons] == scroll)
  1205.                 cons++;
  1206.  
  1207.             if (scroll < 0) scroll = srcwidth - (-scroll) % srcwidth;
  1208.             else scroll %= srcwidth;
  1209.  
  1210.             myclip.min_y = row * rowheight + scrolly;
  1211.             if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
  1212.             myclip.max_y = (row + cons) * rowheight - 1 + scrolly;
  1213.             if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
  1214.  
  1215.             copybitmap(dest,src,0,0,scroll,scrolly,&myclip,transparency,transparent_color);
  1216.             copybitmap(dest,src,0,0,scroll - srcwidth,scrolly,&myclip,transparency,transparent_color);
  1217.  
  1218.             myclip.min_y = row * rowheight + scrolly - srcheight;
  1219.             if (myclip.min_y < clip->min_y) myclip.min_y = clip->min_y;
  1220.             myclip.max_y = (row + cons) * rowheight - 1 + scrolly - srcheight;
  1221.             if (myclip.max_y > clip->max_y) myclip.max_y = clip->max_y;
  1222.  
  1223.             copybitmap(dest,src,0,0,scroll,scrolly - srcheight,&myclip,transparency,transparent_color);
  1224.             copybitmap(dest,src,0,0,scroll - srcwidth,scrolly - srcheight,&myclip,transparency,transparent_color);
  1225.  
  1226.             row += cons;
  1227.         }
  1228.     }
  1229. }
  1230.  
  1231.  
  1232. /* fill a bitmap using the specified pen */
  1233. void fillbitmap(struct osd_bitmap *dest,int pen,const struct rectangle *clip)
  1234. {
  1235.     int sx,sy,ex,ey,y;
  1236.     struct rectangle myclip;
  1237.  
  1238.  
  1239.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  1240.     {
  1241.         if (clip)
  1242.         {
  1243.             myclip.min_x = clip->min_y;
  1244.             myclip.max_x = clip->max_y;
  1245.             myclip.min_y = clip->min_x;
  1246.             myclip.max_y = clip->max_x;
  1247.             clip = &myclip;
  1248.         }
  1249.     }
  1250.     if (Machine->orientation & ORIENTATION_FLIP_X)
  1251.     {
  1252.         if (clip)
  1253.         {
  1254.             int temp;
  1255.  
  1256.  
  1257.             temp = clip->min_x;
  1258.             myclip.min_x = dest->width-1 - clip->max_x;
  1259.             myclip.max_x = dest->width-1 - temp;
  1260.             myclip.min_y = clip->min_y;
  1261.             myclip.max_y = clip->max_y;
  1262.             clip = &myclip;
  1263.         }
  1264.     }
  1265.     if (Machine->orientation & ORIENTATION_FLIP_Y)
  1266.     {
  1267.         if (clip)
  1268.         {
  1269.             int temp;
  1270.  
  1271.  
  1272.             myclip.min_x = clip->min_x;
  1273.             myclip.max_x = clip->max_x;
  1274.             temp = clip->min_y;
  1275.             myclip.min_y = dest->height-1 - clip->max_y;
  1276.             myclip.max_y = dest->height-1 - temp;
  1277.             clip = &myclip;
  1278.         }
  1279.     }
  1280.  
  1281.  
  1282.     sx = 0;
  1283.     ex = dest->width - 1;
  1284.     sy = 0;
  1285.     ey = dest->height - 1;
  1286.  
  1287.     if (clip && sx < clip->min_x) sx = clip->min_x;
  1288.     if (clip && ex > clip->max_x) ex = clip->max_x;
  1289.     if (sx > ex) return;
  1290.     if (clip && sy < clip->min_y) sy = clip->min_y;
  1291.     if (clip && ey > clip->max_y) ey = clip->max_y;
  1292.     if (sy > ey) return;
  1293.  
  1294.     osd_mark_dirty (sx,sy,ex,ey,0);    /* ASG 971011 */
  1295.  
  1296.     /* ASG 980211 */
  1297.     if (dest->depth == 16)
  1298.     {
  1299.         if ((pen >> 8) == (pen & 0xff))
  1300.         {
  1301.             for (y = sy;y <= ey;y++)
  1302.                 memset(&dest->line[y][sx*2],pen&0xff,(ex-sx+1)*2);
  1303.         }
  1304.         else
  1305.         {
  1306.             UINT16 *sp = (UINT16 *)dest->line[sy];
  1307.             int x;
  1308.  
  1309.             for (x = sx;x <= ex;x++)
  1310.                 sp[x] = pen;
  1311.             sp+=sx;
  1312.             for (y = sy+1;y <= ey;y++)
  1313.                 memcpy(&dest->line[y][sx*2],sp,(ex-sx+1)*2);
  1314.         }
  1315.     }
  1316.     else
  1317.     {
  1318.         for (y = sy;y <= ey;y++)
  1319.             memset(&dest->line[y][sx],pen,ex-sx+1);
  1320.     }
  1321. }
  1322.  
  1323.  
  1324. INLINE void common_drawgfxzoom( struct osd_bitmap *dest_bmp,const struct GfxElement *gfx,
  1325.         unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
  1326.         const struct rectangle *clip,int transparency,int transparent_color,
  1327.         int scalex, int scaley,struct osd_bitmap *pri_buffer,UINT32 pri_mask)
  1328. {
  1329.     struct rectangle myclip;
  1330.  
  1331.  
  1332.     pri_mask |= (1<<31);
  1333.  
  1334.     /* only support TRANSPARENCY_PEN, TRANSPARENCY_PENS and TRANSPARENCY_COLOR */
  1335.     if (transparency != TRANSPARENCY_PEN && transparency != TRANSPARENCY_PENS &&
  1336.             transparency != TRANSPARENCY_COLOR)
  1337.     {
  1338.         usrintf_showmessage("drawgfxzoom unsupported trans %02x",transparency);
  1339.         return;
  1340.     }
  1341.  
  1342.     if (transparency == TRANSPARENCY_COLOR)
  1343.         transparent_color = Machine->pens[transparent_color];
  1344.  
  1345.  
  1346.     /*
  1347.     scalex and scaley are 16.16 fixed point numbers
  1348.     1<<15 : shrink to 50%
  1349.     1<<16 : uniform scale
  1350.     1<<17 : double to 200%
  1351.     */
  1352.  
  1353.  
  1354.     if (Machine->orientation & ORIENTATION_SWAP_XY)
  1355.     {
  1356.         int temp;
  1357.  
  1358.         temp = sx;
  1359.         sx = sy;
  1360.         sy = temp;
  1361.  
  1362.         temp = flipx;
  1363.         flipx = flipy;
  1364.         flipy = temp;
  1365.  
  1366.         temp = scalex;
  1367.         scalex = scaley;
  1368.         scaley = temp;
  1369.  
  1370.         if (clip)
  1371.         {
  1372.             /* clip and myclip might be the same, so we need a temporary storage */
  1373.             temp = clip->min_x;
  1374.             myclip.min_x = clip->min_y;
  1375.             myclip.min_y = temp;
  1376.             temp = clip->max_x;
  1377.             myclip.max_x = clip->max_y;
  1378.             myclip.max_y = temp;
  1379.             clip = &myclip;
  1380.         }
  1381.     }
  1382.     if (Machine->orientation & ORIENTATION_FLIP_X)
  1383.     {
  1384.         sx = dest_bmp->width - ((gfx->width * scalex + 0x7fff) >> 16) - sx;
  1385.         if (clip)
  1386.         {
  1387.             int temp;
  1388.  
  1389.  
  1390.             /* clip and myclip might be the same, so we need a temporary storage */
  1391.             temp = clip->min_x;
  1392.             myclip.min_x = dest_bmp->width-1 - clip->max_x;
  1393.             myclip.max_x = dest_bmp->width-1 - temp;
  1394.             myclip.min_y = clip->min_y;
  1395.             myclip.max_y = clip->max_y;
  1396.             clip = &myclip;
  1397.         }
  1398. #ifndef PREROTATE_GFX
  1399.         flipx = !flipx;
  1400. #endif
  1401.     }
  1402.     if (Machine->orientation & ORIENTATION_FLIP_Y)
  1403.     {
  1404.         sy = dest_bmp->height - ((gfx->height * scaley + 0x7fff) >> 16) - sy;
  1405.         if (clip)
  1406.         {
  1407.             int temp;
  1408.  
  1409.  
  1410.             myclip.min_x = clip->min_x;
  1411.             myclip.max_x = clip->max_x;
  1412.             /* clip and myclip might be the same, so we need a temporary storage */
  1413.             temp = clip->min_y;
  1414.             myclip.min_y = dest_bmp->height-1 - clip->max_y;
  1415.             myclip.max_y = dest_bmp->height-1 - temp;
  1416.             clip = &myclip;
  1417.         }
  1418. #ifndef PREROTATE_GFX
  1419.         flipy = !flipy;
  1420. #endif
  1421.     }
  1422.  
  1423.     /* KW 991012 -- Added code to force clip to bitmap boundary */
  1424.     if(clip)
  1425.     {
  1426.         myclip.min_x = clip->min_x;
  1427.         myclip.max_x = clip->max_x;
  1428.         myclip.min_y = clip->min_y;
  1429.         myclip.max_y = clip->max_y;
  1430.  
  1431.         if (myclip.min_x < 0) myclip.min_x = 0;
  1432.         if (myclip.max_x >= dest_bmp->width) myclip.max_x = dest_bmp->width-1;
  1433.         if (myclip.min_y < 0) myclip.min_y = 0;
  1434.         if (myclip.max_y >= dest_bmp->height) myclip.max_y = dest_bmp->height-1;
  1435.  
  1436.         clip=&myclip;
  1437.     }
  1438.  
  1439.  
  1440.     /* ASG 980209 -- added 16-bit version */
  1441.     if (dest_bmp->depth != 16)
  1442.     {
  1443.         if( gfx && gfx->colortable )
  1444.         {
  1445.             const UINT16 *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
  1446.             int source_base = (code % gfx->total_elements) * gfx->height;
  1447.  
  1448.             int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
  1449.             int sprite_screen_width = (scalex*gfx->width+0x8000)>>16;
  1450.  
  1451.             /* compute sprite increment per screen pixel */
  1452.             int dx = (gfx->width<<16)/sprite_screen_width;
  1453.             int dy = (gfx->height<<16)/sprite_screen_height;
  1454.  
  1455.             int ex = sx+sprite_screen_width;
  1456.             int ey = sy+sprite_screen_height;
  1457.  
  1458.             int x_index_base;
  1459.             int y_index;
  1460.  
  1461.             if( flipx )
  1462.             {
  1463.                 x_index_base = (sprite_screen_width-1)*dx;
  1464.                 dx = -dx;
  1465.             }
  1466.             else
  1467.             {
  1468.                 x_index_base = 0;
  1469.             }
  1470.  
  1471.             if( flipy )
  1472.             {
  1473.                 y_index = (sprite_screen_height-1)*dy;
  1474.                 dy = -dy;
  1475.             }
  1476.             else
  1477.             {
  1478.                 y_index = 0;
  1479.             }
  1480.  
  1481.             if( clip )
  1482.             {
  1483.                 if( sx < clip->min_x)
  1484.                 { /* clip left */
  1485.                     int pixels = clip->min_x-sx;
  1486.                     sx += pixels;
  1487.                     x_index_base += pixels*dx;
  1488.                 }
  1489.                 if( sy < clip->min_y )
  1490.                 { /* clip top */
  1491.                     int pixels = clip->min_y-sy;
  1492.                     sy += pixels;
  1493.                     y_index += pixels*dy;
  1494.                 }
  1495.                 /* NS 980211 - fixed incorrect clipping */
  1496.                 if( ex > clip->max_x+1 )
  1497.                 { /* clip right */
  1498.                     int pixels = ex-clip->max_x-1;
  1499.                     ex -= pixels;
  1500.                 }
  1501.                 if( ey > clip->max_y+1 )
  1502.                 { /* clip bottom */
  1503.                     int pixels = ey-clip->max_y-1;
  1504.                     ey -= pixels;
  1505.                 }
  1506.             }
  1507.  
  1508.             if( ex>sx )
  1509.             { /* skip if inner loop doesn't draw anything */
  1510.                 int y;
  1511.  
  1512.                 /* case 1: TRANSPARENCY_PEN */
  1513.                 if (transparency == TRANSPARENCY_PEN)
  1514.                 {
  1515.                     if (pri_buffer)
  1516.                     {
  1517.                         for( y=sy; y<ey; y++ )
  1518.                         {
  1519.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1520.                             UINT8 *dest = dest_bmp->line[y];
  1521.                             UINT8 *pri = pri_buffer->line[y];
  1522.  
  1523.                             int x, x_index = x_index_base;
  1524.                             for( x=sx; x<ex; x++ )
  1525.                             {
  1526.                                 int c = source[x_index>>16];
  1527.                                 if( c != transparent_color )
  1528.                                 {
  1529.                                     if (((1 << pri[x]) & pri_mask) == 0)
  1530.                                         dest[x] = pal[c];
  1531.                                     pri[x] = 31;
  1532.                                 }
  1533.                                 x_index += dx;
  1534.                             }
  1535.  
  1536.                             y_index += dy;
  1537.                         }
  1538.                     }
  1539.                     else
  1540.                     {
  1541.                         for( y=sy; y<ey; y++ )
  1542.                         {
  1543.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1544.                             UINT8 *dest = dest_bmp->line[y];
  1545.  
  1546.                             int x, x_index = x_index_base;
  1547.                             for( x=sx; x<ex; x++ )
  1548.                             {
  1549.                                 int c = source[x_index>>16];
  1550.                                 if( c != transparent_color ) dest[x] = pal[c];
  1551.                                 x_index += dx;
  1552.                             }
  1553.  
  1554.                             y_index += dy;
  1555.                         }
  1556.                     }
  1557.                 }
  1558.  
  1559.                 /* case 2: TRANSPARENCY_PENS */
  1560.                 if (transparency == TRANSPARENCY_PENS)
  1561.                 {
  1562.                     if (pri_buffer)
  1563.                     {
  1564.                         for( y=sy; y<ey; y++ )
  1565.                         {
  1566.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1567.                             UINT8 *dest = dest_bmp->line[y];
  1568.                             UINT8 *pri = pri_buffer->line[y];
  1569.  
  1570.                             int x, x_index = x_index_base;
  1571.                             for( x=sx; x<ex; x++ )
  1572.                             {
  1573.                                 int c = source[x_index>>16];
  1574.                                 if (((1 << c) & transparent_color) == 0)
  1575.                                 {
  1576.                                     if (((1 << pri[x]) & pri_mask) == 0)
  1577.                                         dest[x] = pal[c];
  1578.                                     pri[x] = 31;
  1579.                                 }
  1580.                                 x_index += dx;
  1581.                             }
  1582.  
  1583.                             y_index += dy;
  1584.                         }
  1585.                     }
  1586.                     else
  1587.                     {
  1588.                         for( y=sy; y<ey; y++ )
  1589.                         {
  1590.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1591.                             UINT8 *dest = dest_bmp->line[y];
  1592.  
  1593.                             int x, x_index = x_index_base;
  1594.                             for( x=sx; x<ex; x++ )
  1595.                             {
  1596.                                 int c = source[x_index>>16];
  1597.                                 if (((1 << c) & transparent_color) == 0)
  1598.                                     dest[x] = pal[c];
  1599.                                 x_index += dx;
  1600.                             }
  1601.  
  1602.                             y_index += dy;
  1603.                         }
  1604.                     }
  1605.                 }
  1606.  
  1607.                 /* case 3: TRANSPARENCY_COLOR */
  1608.                 else if (transparency == TRANSPARENCY_COLOR)
  1609.                 {
  1610.                     if (pri_buffer)
  1611.                     {
  1612.                         for( y=sy; y<ey; y++ )
  1613.                         {
  1614.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1615.                             UINT8 *dest = dest_bmp->line[y];
  1616.                             UINT8 *pri = pri_buffer->line[y];
  1617.  
  1618.                             int x, x_index = x_index_base;
  1619.                             for( x=sx; x<ex; x++ )
  1620.                             {
  1621.                                 int c = pal[source[x_index>>16]];
  1622.                                 if( c != transparent_color )
  1623.                                 {
  1624.                                     if (((1 << pri[x]) & pri_mask) == 0)
  1625.                                         dest[x] = c;
  1626.                                     pri[x] = 31;
  1627.                                 }
  1628.                                 x_index += dx;
  1629.                             }
  1630.  
  1631.                             y_index += dy;
  1632.                         }
  1633.                     }
  1634.                     else
  1635.                     {
  1636.                         for( y=sy; y<ey; y++ )
  1637.                         {
  1638.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1639.                             UINT8 *dest = dest_bmp->line[y];
  1640.  
  1641.                             int x, x_index = x_index_base;
  1642.                             for( x=sx; x<ex; x++ )
  1643.                             {
  1644.                                 int c = pal[source[x_index>>16]];
  1645.                                 if( c != transparent_color ) dest[x] = c;
  1646.                                 x_index += dx;
  1647.                             }
  1648.  
  1649.                             y_index += dy;
  1650.                         }
  1651.                     }
  1652.                 }
  1653.             }
  1654.  
  1655.         }
  1656.     }
  1657.  
  1658.     /* ASG 980209 -- new 16-bit part */
  1659.     else
  1660.     {
  1661.         if( gfx && gfx->colortable )
  1662.         {
  1663.             const UINT16 *pal = &gfx->colortable[gfx->color_granularity * (color % gfx->total_colors)]; /* ASG 980209 */
  1664.             int source_base = (code % gfx->total_elements) * gfx->height;
  1665.  
  1666.             int sprite_screen_height = (scaley*gfx->height+0x8000)>>16;
  1667.             int sprite_screen_width = (scalex*gfx->width+0x8000)>>16;
  1668.  
  1669.             /* compute sprite increment per screen pixel */
  1670.             int dx = (gfx->width<<16)/sprite_screen_width;
  1671.             int dy = (gfx->height<<16)/sprite_screen_height;
  1672.  
  1673.             int ex = sx+sprite_screen_width;
  1674.             int ey = sy+sprite_screen_height;
  1675.  
  1676.             int x_index_base;
  1677.             int y_index;
  1678.  
  1679.             if( flipx )
  1680.             {
  1681.                 x_index_base = (sprite_screen_width-1)*dx;
  1682.                 dx = -dx;
  1683.             }
  1684.             else
  1685.             {
  1686.                 x_index_base = 0;
  1687.             }
  1688.  
  1689.             if( flipy )
  1690.             {
  1691.                 y_index = (sprite_screen_height-1)*dy;
  1692.                 dy = -dy;
  1693.             }
  1694.             else
  1695.             {
  1696.                 y_index = 0;
  1697.             }
  1698.  
  1699.             if( clip )
  1700.             {
  1701.                 if( sx < clip->min_x)
  1702.                 { /* clip left */
  1703.                     int pixels = clip->min_x-sx;
  1704.                     sx += pixels;
  1705.                     x_index_base += pixels*dx;
  1706.                 }
  1707.                 if( sy < clip->min_y )
  1708.                 { /* clip top */
  1709.                     int pixels = clip->min_y-sy;
  1710.                     sy += pixels;
  1711.                     y_index += pixels*dy;
  1712.                 }
  1713.                 /* NS 980211 - fixed incorrect clipping */
  1714.                 if( ex > clip->max_x+1 )
  1715.                 { /* clip right */
  1716.                     int pixels = ex-clip->max_x-1;
  1717.                     ex -= pixels;
  1718.                 }
  1719.                 if( ey > clip->max_y+1 )
  1720.                 { /* clip bottom */
  1721.                     int pixels = ey-clip->max_y-1;
  1722.                     ey -= pixels;
  1723.                 }
  1724.             }
  1725.  
  1726.             if( ex>sx )
  1727.             { /* skip if inner loop doesn't draw anything */
  1728.                 int y;
  1729.  
  1730.                 /* case 1: TRANSPARENCY_PEN */
  1731.                 if (transparency == TRANSPARENCY_PEN)
  1732.                 {
  1733.                     if (pri_buffer)
  1734.                     {
  1735.                         for( y=sy; y<ey; y++ )
  1736.                         {
  1737.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1738.                             UINT16 *dest = (UINT16 *)dest_bmp->line[y];
  1739.                             UINT8 *pri = pri_buffer->line[y];
  1740.  
  1741.                             int x, x_index = x_index_base;
  1742.                             for( x=sx; x<ex; x++ )
  1743.                             {
  1744.                                 int c = source[x_index>>16];
  1745.                                 if( c != transparent_color )
  1746.                                 {
  1747.                                     if (((1 << pri[x]) & pri_mask) == 0)
  1748.                                         dest[x] = pal[c];
  1749.                                     pri[x] = 31;
  1750.                                 }
  1751.                                 x_index += dx;
  1752.                             }
  1753.  
  1754.                             y_index += dy;
  1755.                         }
  1756.                     }
  1757.                     else
  1758.                     {
  1759.                         for( y=sy; y<ey; y++ )
  1760.                         {
  1761.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1762.                             UINT16 *dest = (UINT16 *)dest_bmp->line[y];
  1763.  
  1764.                             int x, x_index = x_index_base;
  1765.                             for( x=sx; x<ex; x++ )
  1766.                             {
  1767.                                 int c = source[x_index>>16];
  1768.                                 if( c != transparent_color ) dest[x] = pal[c];
  1769.                                 x_index += dx;
  1770.                             }
  1771.  
  1772.                             y_index += dy;
  1773.                         }
  1774.                     }
  1775.                 }
  1776.  
  1777.                 /* case 2: TRANSPARENCY_PEN */
  1778.                 if (transparency == TRANSPARENCY_PEN)
  1779.                 {
  1780.                     if (pri_buffer)
  1781.                     {
  1782.                         for( y=sy; y<ey; y++ )
  1783.                         {
  1784.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1785.                             UINT16 *dest = (UINT16 *)dest_bmp->line[y];
  1786.                             UINT8 *pri = pri_buffer->line[y];
  1787.  
  1788.                             int x, x_index = x_index_base;
  1789.                             for( x=sx; x<ex; x++ )
  1790.                             {
  1791.                                 int c = source[x_index>>16];
  1792.                                 if (((1 << c) & transparent_color) == 0)
  1793.                                 {
  1794.                                     if (((1 << pri[x]) & pri_mask) == 0)
  1795.                                         dest[x] = pal[c];
  1796.                                     pri[x] = 31;
  1797.                                 }
  1798.                                 x_index += dx;
  1799.                             }
  1800.  
  1801.                             y_index += dy;
  1802.                         }
  1803.                     }
  1804.                     else
  1805.                     {
  1806.                         for( y=sy; y<ey; y++ )
  1807.                         {
  1808.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1809.                             UINT16 *dest = (UINT16 *)dest_bmp->line[y];
  1810.  
  1811.                             int x, x_index = x_index_base;
  1812.                             for( x=sx; x<ex; x++ )
  1813.                             {
  1814.                                 int c = source[x_index>>16];
  1815.                                 if (((1 << c) & transparent_color) == 0)
  1816.                                     dest[x] = pal[c];
  1817.                                 x_index += dx;
  1818.                             }
  1819.  
  1820.                             y_index += dy;
  1821.                         }
  1822.                     }
  1823.                 }
  1824.  
  1825.                 /* case 3: TRANSPARENCY_COLOR */
  1826.                 else if (transparency == TRANSPARENCY_COLOR)
  1827.                 {
  1828.                     if (pri_buffer)
  1829.                     {
  1830.                         for( y=sy; y<ey; y++ )
  1831.                         {
  1832.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1833.                             UINT16 *dest = (UINT16 *)dest_bmp->line[y];
  1834.                             UINT8 *pri = pri_buffer->line[y];
  1835.  
  1836.                             int x, x_index = x_index_base;
  1837.                             for( x=sx; x<ex; x++ )
  1838.                             {
  1839.                                 int c = pal[source[x_index>>16]];
  1840.                                 if( c != transparent_color )
  1841.                                 {
  1842.                                     if (((1 << pri[x]) & pri_mask) == 0)
  1843.                                         dest[x] = c;
  1844.                                     pri[x] = 31;
  1845.                                 }
  1846.                                 x_index += dx;
  1847.                             }
  1848.  
  1849.                             y_index += dy;
  1850.                         }
  1851.                     }
  1852.                     else
  1853.                     {
  1854.                         for( y=sy; y<ey; y++ )
  1855.                         {
  1856.                             UINT8 *source = gfx->gfxdata + (source_base+(y_index>>16)) * gfx->line_modulo;
  1857.                             UINT16 *dest = (UINT16 *)dest_bmp->line[y];
  1858.  
  1859.                             int x, x_index = x_index_base;
  1860.                             for( x=sx; x<ex; x++ )
  1861.                             {
  1862.                                 int c = pal[source[x_index>>16]];
  1863.                                 if( c != transparent_color ) dest[x] = c;
  1864.                                 x_index += dx;
  1865.                             }
  1866.  
  1867.                             y_index += dy;
  1868.                         }
  1869.                     }
  1870.                 }
  1871.             }
  1872.         }
  1873.     }
  1874. }
  1875.  
  1876. void drawgfxzoom( struct osd_bitmap *dest_bmp,const struct GfxElement *gfx,
  1877.         unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
  1878.         const struct rectangle *clip,int transparency,int transparent_color,int scalex, int scaley)
  1879. {
  1880.     common_drawgfxzoom(dest_bmp,gfx,code,color,flipx,flipy,sx,sy,
  1881.             clip,transparency,transparent_color,scalex,scaley,NULL,0);
  1882. }
  1883.  
  1884. void pdrawgfxzoom( struct osd_bitmap *dest_bmp,const struct GfxElement *gfx,
  1885.         unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
  1886.         const struct rectangle *clip,int transparency,int transparent_color,int scalex, int scaley,
  1887.         UINT32 priority_mask)
  1888. {
  1889.     common_drawgfxzoom(dest_bmp,gfx,code,color,flipx,flipy,sx,sy,
  1890.             clip,transparency,transparent_color,scalex,scaley,priority_bitmap,priority_mask);
  1891. }
  1892.  
  1893.  
  1894. void plot_pixel2(struct osd_bitmap *bitmap1,struct osd_bitmap *bitmap2,int x,int y,int pen)
  1895. {
  1896.     plot_pixel(bitmap1, x, y, pen);
  1897.     plot_pixel(bitmap2, x, y, pen);
  1898. }
  1899.  
  1900. static void pp_8_nd(struct osd_bitmap *b,int x,int y,int p)  { b->line[y][x] = p; }
  1901. static void pp_8_nd_fx(struct osd_bitmap *b,int x,int y,int p)  { b->line[y][b->width-1-x] = p; }
  1902. static void pp_8_nd_fy(struct osd_bitmap *b,int x,int y,int p)  { b->line[b->height-1-y][x] = p; }
  1903. static void pp_8_nd_fxy(struct osd_bitmap *b,int x,int y,int p)  { b->line[b->height-1-y][b->width-1-x] = p; }
  1904. static void pp_8_nd_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[x][y] = p; }
  1905. static void pp_8_nd_fx_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[x][b->width-1-y] = p; }
  1906. static void pp_8_nd_fy_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[b->height-1-x][y] = p; }
  1907. static void pp_8_nd_fxy_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[b->height-1-x][b->width-1-y] = p; }
  1908.  
  1909. static void pp_8_d(struct osd_bitmap *b,int x,int y,int p)  { b->line[y][x] = p; osd_mark_dirty (x,y,x,y,0); }
  1910. static void pp_8_d_fx(struct osd_bitmap *b,int x,int y,int p)  { int newx = b->width-1-x;  b->line[y][newx] = p; osd_mark_dirty (newx,y,newx,y,0); }
  1911. static void pp_8_d_fy(struct osd_bitmap *b,int x,int y,int p)  { int newy = b->height-1-y; b->line[newy][x] = p; osd_mark_dirty (x,newy,x,newy,0); }
  1912. static void pp_8_d_fxy(struct osd_bitmap *b,int x,int y,int p)  { int newx = b->width-1-x; int newy = b->height-1-y; b->line[newy][newx] = p; osd_mark_dirty (newx,newy,newx,newy,0); }
  1913. static void pp_8_d_s(struct osd_bitmap *b,int x,int y,int p)  { b->line[x][y] = p; osd_mark_dirty (y,x,y,x,0); }
  1914. static void pp_8_d_fx_s(struct osd_bitmap *b,int x,int y,int p)  { int newy = b->width-1-y; b->line[x][newy] = p; osd_mark_dirty (newy,x,newy,x,0); }
  1915. static void pp_8_d_fy_s(struct osd_bitmap *b,int x,int y,int p)  { int newx = b->height-1-x; b->line[newx][y] = p; osd_mark_dirty (y,newx,y,newx,0); }
  1916. static void pp_8_d_fxy_s(struct osd_bitmap *b,int x,int y,int p)  { int newx = b->height-1-x; int newy = b->width-1-y; b->line[newx][newy] = p; osd_mark_dirty (newy,newx,newy,newx,0); }
  1917.  
  1918. static void pp_16_nd(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[y])[x] = p; }
  1919. static void pp_16_nd_fx(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[y])[b->width-1-x] = p; }
  1920. static void pp_16_nd_fy(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[b->height-1-y])[x] = p; }
  1921. static void pp_16_nd_fxy(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[b->height-1-y])[b->width-1-x] = p; }
  1922. static void pp_16_nd_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[x])[y] = p; }
  1923. static void pp_16_nd_fx_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[x])[b->width-1-y] = p; }
  1924. static void pp_16_nd_fy_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[b->height-1-x])[y] = p; }
  1925. static void pp_16_nd_fxy_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[b->height-1-x])[b->width-1-y] = p; }
  1926.  
  1927. static void pp_16_d(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[y])[x] = p; osd_mark_dirty (x,y,x,y,0); }
  1928. static void pp_16_d_fx(struct osd_bitmap *b,int x,int y,int p)  { int newx = b->width-1-x;  ((UINT16 *)b->line[y])[newx] = p; osd_mark_dirty (newx,y,newx,y,0); }
  1929. static void pp_16_d_fy(struct osd_bitmap *b,int x,int y,int p)  { int newy = b->height-1-y; ((UINT16 *)b->line[newy])[x] = p; osd_mark_dirty (x,newy,x,newy,0); }
  1930. static void pp_16_d_fxy(struct osd_bitmap *b,int x,int y,int p)  { int newx = b->width-1-x; int newy = b->height-1-y; ((UINT16 *)b->line[newy])[newx] = p; osd_mark_dirty (newx,newy,newx,newy,0); }
  1931. static void pp_16_d_s(struct osd_bitmap *b,int x,int y,int p)  { ((UINT16 *)b->line[x])[y] = p; osd_mark_dirty (y,x,y,x,0); }
  1932. static void pp_16_d_fx_s(struct osd_bitmap *b,int x,int y,int p)  { int newy = b->width-1-y; ((UINT16 *)b->line[x])[newy] = p; osd_mark_dirty (newy,x,newy,x,0); }
  1933. static void pp_16_d_fy_s(struct osd_bitmap *b,int x,int y,int p)  { int newx = b->height-1-x; ((UINT16 *)b->line[newx])[y] = p; osd_mark_dirty (y,newx,y,newx,0); }
  1934. static void pp_16_d_fxy_s(struct osd_bitmap *b,int x,int y,int p)  { int newx = b->height-1-x; int newy = b->width-1-y; ((UINT16 *)b->line[newx])[newy] = p; osd_mark_dirty (newy,newx,newy,newx,0); }
  1935.  
  1936.  
  1937. static int rp_8(struct osd_bitmap *b,int x,int y)  { return b->line[y][x]; }
  1938. static int rp_8_fx(struct osd_bitmap *b,int x,int y)  { return b->line[y][b->width-1-x]; }
  1939. static int rp_8_fy(struct osd_bitmap *b,int x,int y)  { return b->line[b->height-1-y][x]; }
  1940. static int rp_8_fxy(struct osd_bitmap *b,int x,int y)  { return b->line[b->height-1-y][b->width-1-x]; }
  1941. static int rp_8_s(struct osd_bitmap *b,int x,int y)  { return b->line[x][y]; }
  1942. static int rp_8_fx_s(struct osd_bitmap *b,int x,int y)  { return b->line[x][b->width-1-y]; }
  1943. static int rp_8_fy_s(struct osd_bitmap *b,int x,int y)  { return b->line[b->height-1-x][y]; }
  1944. static int rp_8_fxy_s(struct osd_bitmap *b,int x,int y)  { return b->line[b->height-1-x][b->width-1-y]; }
  1945.  
  1946. static int rp_16(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[y])[x]; }
  1947. static int rp_16_fx(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[y])[b->width-1-x]; }
  1948. static int rp_16_fy(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[b->height-1-y])[x]; }
  1949. static int rp_16_fxy(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[b->height-1-y])[b->width-1-x]; }
  1950. static int rp_16_s(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[x])[y]; }
  1951. static int rp_16_fx_s(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[x])[b->width-1-y]; }
  1952. static int rp_16_fy_s(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[b->height-1-x])[y]; }
  1953. static int rp_16_fxy_s(struct osd_bitmap *b,int x,int y)  { return ((UINT16 *)b->line[b->height-1-x])[b->width-1-y]; }
  1954.  
  1955.  
  1956. static plot_pixel_proc pps_8_nd[] =
  1957.         { pp_8_nd,      pp_8_nd_fx,   pp_8_nd_fy,      pp_8_nd_fxy,
  1958.           pp_8_nd_s, pp_8_nd_fx_s, pp_8_nd_fy_s, pp_8_nd_fxy_s };
  1959.  
  1960. static plot_pixel_proc pps_8_d[] =
  1961.         { pp_8_d,     pp_8_d_fx,   pp_8_d_fy,      pp_8_d_fxy,
  1962.           pp_8_d_s, pp_8_d_fx_s, pp_8_d_fy_s, pp_8_d_fxy_s };
  1963.  
  1964. static plot_pixel_proc pps_16_nd[] =
  1965.         { pp_16_nd,   pp_16_nd_fx,   pp_16_nd_fy,     pp_16_nd_fxy,
  1966.           pp_16_nd_s, pp_16_nd_fx_s, pp_16_nd_fy_s, pp_16_nd_fxy_s };
  1967.  
  1968. static plot_pixel_proc pps_16_d[] =
  1969.         { pp_16_d,   pp_16_d_fx,   pp_16_d_fy,      pp_16_d_fxy,
  1970.           pp_16_d_s, pp_16_d_fx_s, pp_16_d_fy_s, pp_16_d_fxy_s };
  1971.  
  1972.  
  1973. static read_pixel_proc rps_8[] =
  1974.         { rp_8,      rp_8_fx,   rp_8_fy,    rp_8_fxy,
  1975.           rp_8_s, rp_8_fx_s, rp_8_fy_s, rp_8_fxy_s };
  1976.  
  1977. static read_pixel_proc rps_16[] =
  1978.         { rp_16,   rp_16_fx,   rp_16_fy,   rp_16_fxy,
  1979.           rp_16_s, rp_16_fx_s, rp_16_fy_s, rp_16_fxy_s };
  1980.  
  1981.  
  1982. void set_pixel_functions(void)
  1983. {
  1984.     if (Machine->color_depth == 8)
  1985.     {
  1986.         read_pixel = rps_8[Machine->orientation];
  1987.  
  1988.         if (Machine->drv->video_attributes & VIDEO_SUPPORTS_DIRTY)
  1989.             plot_pixel = pps_8_d[Machine->orientation];
  1990.         else
  1991.             plot_pixel = pps_8_nd[Machine->orientation];
  1992.     }
  1993.     else
  1994.     {
  1995.         read_pixel = rps_16[Machine->orientation];
  1996.  
  1997.         if (Machine->drv->video_attributes & VIDEO_SUPPORTS_DIRTY)
  1998.             plot_pixel = pps_16_d[Machine->orientation];
  1999.         else
  2000.             plot_pixel = pps_16_nd[Machine->orientation];
  2001.     }
  2002.  
  2003.     /* while we're here, fill in the raw drawing mode table as well */
  2004.     is_raw[TRANSPARENCY_NONE_RAW]    = 1;
  2005.     is_raw[TRANSPARENCY_PEN_RAW]     = 1;
  2006.     is_raw[TRANSPARENCY_PENS_RAW]    = 1;
  2007.     is_raw[TRANSPARENCY_THROUGH_RAW] = 1;
  2008.     is_raw[TRANSPARENCY_BLEND_RAW]   = 1;
  2009. }
  2010.  
  2011. #else /* DECLARE */
  2012.  
  2013. /* -------------------- included inline section --------------------- */
  2014.  
  2015. /* don't put this file in the makefile, it is #included by common.c to */
  2016. /* generate 8-bit and 16-bit versions                                  */
  2017.  
  2018. DECLARE(blockmove_8toN_opaque,(
  2019.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2020.         DATA_TYPE *dstdata,int dstmodulo,
  2021.         const UINT16 *paldata),
  2022. {
  2023.     DATA_TYPE *end;
  2024.  
  2025.     srcmodulo -= srcwidth;
  2026.     dstmodulo -= srcwidth;
  2027.  
  2028.     while (srcheight)
  2029.     {
  2030.         end = dstdata + srcwidth;
  2031.         while (dstdata <= end - 8)
  2032.         {
  2033.             dstdata[0] = paldata[srcdata[0]];
  2034.             dstdata[1] = paldata[srcdata[1]];
  2035.             dstdata[2] = paldata[srcdata[2]];
  2036.             dstdata[3] = paldata[srcdata[3]];
  2037.             dstdata[4] = paldata[srcdata[4]];
  2038.             dstdata[5] = paldata[srcdata[5]];
  2039.             dstdata[6] = paldata[srcdata[6]];
  2040.             dstdata[7] = paldata[srcdata[7]];
  2041.             dstdata += 8;
  2042.             srcdata += 8;
  2043.         }
  2044.         while (dstdata < end)
  2045.             *(dstdata++) = paldata[*(srcdata++)];
  2046.  
  2047.         srcdata += srcmodulo;
  2048.         dstdata += dstmodulo;
  2049.         srcheight--;
  2050.     }
  2051. })
  2052.  
  2053. DECLARE(blockmove_8toN_opaque_flipx,(
  2054.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2055.         DATA_TYPE *dstdata,int dstmodulo,
  2056.         const UINT16 *paldata),
  2057. {
  2058.     DATA_TYPE *end;
  2059.  
  2060.     srcmodulo += srcwidth;
  2061.     dstmodulo -= srcwidth;
  2062.     //srcdata += srcwidth-1;
  2063.  
  2064.     while (srcheight)
  2065.     {
  2066.         end = dstdata + srcwidth;
  2067.         while (dstdata <= end - 8)
  2068.         {
  2069.             srcdata -= 8;
  2070.             dstdata[0] = paldata[srcdata[8]];
  2071.             dstdata[1] = paldata[srcdata[7]];
  2072.             dstdata[2] = paldata[srcdata[6]];
  2073.             dstdata[3] = paldata[srcdata[5]];
  2074.             dstdata[4] = paldata[srcdata[4]];
  2075.             dstdata[5] = paldata[srcdata[3]];
  2076.             dstdata[6] = paldata[srcdata[2]];
  2077.             dstdata[7] = paldata[srcdata[1]];
  2078.             dstdata += 8;
  2079.         }
  2080.         while (dstdata < end)
  2081.             *(dstdata++) = paldata[*(srcdata--)];
  2082.  
  2083.         srcdata += srcmodulo;
  2084.         dstdata += dstmodulo;
  2085.         srcheight--;
  2086.     }
  2087. })
  2088.  
  2089. DECLARE(blockmove_8toN_opaque_pri,(
  2090.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2091.         DATA_TYPE *dstdata,int dstmodulo,
  2092.         const UINT16 *paldata,UINT8 *pridata,UINT32 pmask),
  2093. {
  2094.     DATA_TYPE *end;
  2095.  
  2096.     pmask |= (1<<31);
  2097.  
  2098.     srcmodulo -= srcwidth;
  2099.     dstmodulo -= srcwidth;
  2100.  
  2101.     while (srcheight)
  2102.     {
  2103.         end = dstdata + srcwidth;
  2104.         while (dstdata <= end - 8)
  2105.         {
  2106.             if (((1 << pridata[0]) & pmask) == 0) dstdata[0] = paldata[srcdata[0]];
  2107.             if (((1 << pridata[1]) & pmask) == 0) dstdata[1] = paldata[srcdata[1]];
  2108.             if (((1 << pridata[2]) & pmask) == 0) dstdata[2] = paldata[srcdata[2]];
  2109.             if (((1 << pridata[3]) & pmask) == 0) dstdata[3] = paldata[srcdata[3]];
  2110.             if (((1 << pridata[4]) & pmask) == 0) dstdata[4] = paldata[srcdata[4]];
  2111.             if (((1 << pridata[5]) & pmask) == 0) dstdata[5] = paldata[srcdata[5]];
  2112.             if (((1 << pridata[6]) & pmask) == 0) dstdata[6] = paldata[srcdata[6]];
  2113.             if (((1 << pridata[7]) & pmask) == 0) dstdata[7] = paldata[srcdata[7]];
  2114.             memset(pridata,31,8);
  2115.             srcdata += 8;
  2116.             dstdata += 8;
  2117.             pridata += 8;
  2118.         }
  2119.         while (dstdata < end)
  2120.         {
  2121.             if (((1 << *pridata) & pmask) == 0)
  2122.                 *dstdata = paldata[*srcdata];
  2123.             *pridata = 31;
  2124.             srcdata++;
  2125.             dstdata++;
  2126.             pridata++;
  2127.         }
  2128.  
  2129.         srcdata += srcmodulo;
  2130.         dstdata += dstmodulo;
  2131.         pridata += dstmodulo;
  2132.         srcheight--;
  2133.     }
  2134. })
  2135.  
  2136. DECLARE(blockmove_8toN_opaque_pri_flipx,(
  2137.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2138.         DATA_TYPE *dstdata,int dstmodulo,
  2139.         const UINT16 *paldata,UINT8 *pridata,UINT32 pmask),
  2140. {
  2141.     DATA_TYPE *end;
  2142.  
  2143.     pmask |= (1<<31);
  2144.  
  2145.     srcmodulo += srcwidth;
  2146.     dstmodulo -= srcwidth;
  2147.     //srcdata += srcwidth-1;
  2148.  
  2149.     while (srcheight)
  2150.     {
  2151.         end = dstdata + srcwidth;
  2152.         while (dstdata <= end - 8)
  2153.         {
  2154.             srcdata -= 8;
  2155.             if (((1 << pridata[0]) & pmask) == 0) dstdata[0] = paldata[srcdata[8]];
  2156.             if (((1 << pridata[1]) & pmask) == 0) dstdata[1] = paldata[srcdata[7]];
  2157.             if (((1 << pridata[2]) & pmask) == 0) dstdata[2] = paldata[srcdata[6]];
  2158.             if (((1 << pridata[3]) & pmask) == 0) dstdata[3] = paldata[srcdata[5]];
  2159.             if (((1 << pridata[4]) & pmask) == 0) dstdata[4] = paldata[srcdata[4]];
  2160.             if (((1 << pridata[5]) & pmask) == 0) dstdata[5] = paldata[srcdata[3]];
  2161.             if (((1 << pridata[6]) & pmask) == 0) dstdata[6] = paldata[srcdata[2]];
  2162.             if (((1 << pridata[7]) & pmask) == 0) dstdata[7] = paldata[srcdata[1]];
  2163.             memset(pridata,31,8);
  2164.             dstdata += 8;
  2165.             pridata += 8;
  2166.         }
  2167.         while (dstdata < end)
  2168.         {
  2169.             if (((1 << *pridata) & pmask) == 0)
  2170.                 *dstdata = paldata[*srcdata];
  2171.             *pridata = 31;
  2172.             srcdata--;
  2173.             dstdata++;
  2174.             pridata++;
  2175.         }
  2176.  
  2177.         srcdata += srcmodulo;
  2178.         dstdata += dstmodulo;
  2179.         pridata += dstmodulo;
  2180.         srcheight--;
  2181.     }
  2182. })
  2183.  
  2184.  
  2185. DECLARE(blockmove_8toN_opaque_raw,(
  2186.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2187.         DATA_TYPE *dstdata,int dstmodulo,
  2188.         unsigned int colorbase),
  2189. {
  2190.     DATA_TYPE *end;
  2191.  
  2192.     srcmodulo -= srcwidth;
  2193.     dstmodulo -= srcwidth;
  2194.  
  2195.     while (srcheight)
  2196.     {
  2197.         end = dstdata + srcwidth;
  2198.         while (dstdata <= end - 8)
  2199.         {
  2200.             dstdata[0] = colorbase + srcdata[0];
  2201.             dstdata[1] = colorbase + srcdata[1];
  2202.             dstdata[2] = colorbase + srcdata[2];
  2203.             dstdata[3] = colorbase + srcdata[3];
  2204.             dstdata[4] = colorbase + srcdata[4];
  2205.             dstdata[5] = colorbase + srcdata[5];
  2206.             dstdata[6] = colorbase + srcdata[6];
  2207.             dstdata[7] = colorbase + srcdata[7];
  2208.             dstdata += 8;
  2209.             srcdata += 8;
  2210.         }
  2211.         while (dstdata < end)
  2212.             *(dstdata++) = colorbase + *(srcdata++);
  2213.  
  2214.         srcdata += srcmodulo;
  2215.         dstdata += dstmodulo;
  2216.         srcheight--;
  2217.     }
  2218. })
  2219.  
  2220. DECLARE(blockmove_8toN_opaque_raw_flipx,(
  2221.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2222.         DATA_TYPE *dstdata,int dstmodulo,
  2223.         unsigned int colorbase),
  2224. {
  2225.     DATA_TYPE *end;
  2226.  
  2227.     srcmodulo += srcwidth;
  2228.     dstmodulo -= srcwidth;
  2229.     //srcdata += srcwidth-1;
  2230.  
  2231.     while (srcheight)
  2232.     {
  2233.         end = dstdata + srcwidth;
  2234.         while (dstdata <= end - 8)
  2235.         {
  2236.             srcdata -= 8;
  2237.             dstdata[0] = colorbase + srcdata[8];
  2238.             dstdata[1] = colorbase + srcdata[7];
  2239.             dstdata[2] = colorbase + srcdata[6];
  2240.             dstdata[3] = colorbase + srcdata[5];
  2241.             dstdata[4] = colorbase + srcdata[4];
  2242.             dstdata[5] = colorbase + srcdata[3];
  2243.             dstdata[6] = colorbase + srcdata[2];
  2244.             dstdata[7] = colorbase + srcdata[1];
  2245.             dstdata += 8;
  2246.         }
  2247.         while (dstdata < end)
  2248.             *(dstdata++) = colorbase + *(srcdata--);
  2249.  
  2250.         srcdata += srcmodulo;
  2251.         dstdata += dstmodulo;
  2252.         srcheight--;
  2253.     }
  2254. })
  2255.  
  2256. DECLARE(blockmove_8toN_transpen,(
  2257.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2258.         DATA_TYPE *dstdata,int dstmodulo,
  2259.         const UINT16 *paldata,int transpen),
  2260. {
  2261.     DATA_TYPE *end;
  2262.     int trans4;
  2263.     UINT32 *sd4;
  2264.  
  2265.     srcmodulo -= srcwidth;
  2266.     dstmodulo -= srcwidth;
  2267.  
  2268.     trans4 = transpen * 0x01010101;
  2269.  
  2270.     while (srcheight)
  2271.     {
  2272.         end = dstdata + srcwidth;
  2273.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2274.         {
  2275.             int col;
  2276.  
  2277.             col = *(srcdata++);
  2278.             if (col != transpen) *dstdata = paldata[col];
  2279.             dstdata++;
  2280.         }
  2281.         sd4 = (UINT32 *)srcdata;
  2282.         while (dstdata <= end - 4)
  2283.         {
  2284.             UINT32 col4;
  2285.  
  2286.             if ((col4 = *(sd4++)) != trans4)
  2287.             {
  2288.                 UINT32 xod4;
  2289.  
  2290.                 xod4 = col4 ^ trans4;
  2291.                 if (xod4 & 0x000000ff) dstdata[BL0] = paldata[(col4) & 0xff];
  2292.                 if (xod4 & 0x0000ff00) dstdata[BL1] = paldata[(col4 >>  8) & 0xff];
  2293.                 if (xod4 & 0x00ff0000) dstdata[BL2] = paldata[(col4 >> 16) & 0xff];
  2294.                 if (xod4 & 0xff000000) dstdata[BL3] = paldata[col4 >> 24];
  2295.             }
  2296.             dstdata += 4;
  2297.         }
  2298.         srcdata = (UINT8 *)sd4;
  2299.         while (dstdata < end)
  2300.         {
  2301.             int col;
  2302.  
  2303.             col = *(srcdata++);
  2304.             if (col != transpen) *dstdata = paldata[col];
  2305.             dstdata++;
  2306.         }
  2307.  
  2308.         srcdata += srcmodulo;
  2309.         dstdata += dstmodulo;
  2310.         srcheight--;
  2311.     }
  2312. })
  2313.  
  2314. DECLARE(blockmove_8toN_transpen_flipx,(
  2315.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2316.         DATA_TYPE *dstdata,int dstmodulo,
  2317.         const UINT16 *paldata,int transpen),
  2318. {
  2319.     DATA_TYPE *end;
  2320.     int trans4;
  2321.     UINT32 *sd4;
  2322.  
  2323.     srcmodulo += srcwidth;
  2324.     dstmodulo -= srcwidth;
  2325.     //srcdata += srcwidth-1;
  2326.     srcdata -= 3;
  2327.  
  2328.     trans4 = transpen * 0x01010101;
  2329.  
  2330.     while (srcheight)
  2331.     {
  2332.         end = dstdata + srcwidth;
  2333.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2334.         {
  2335.             int col;
  2336.  
  2337.             col = srcdata[3];
  2338.             srcdata--;
  2339.             if (col != transpen) *dstdata = paldata[col];
  2340.             dstdata++;
  2341.         }
  2342.         sd4 = (UINT32 *)srcdata;
  2343.         while (dstdata <= end - 4)
  2344.         {
  2345.             UINT32 col4;
  2346.  
  2347.             if ((col4 = *(sd4--)) != trans4)
  2348.             {
  2349.                 UINT32 xod4;
  2350.  
  2351.                 xod4 = col4 ^ trans4;
  2352.                 if (xod4 & 0xff000000) dstdata[BL0] = paldata[col4 >> 24];
  2353.                 if (xod4 & 0x00ff0000) dstdata[BL1] = paldata[(col4 >> 16) & 0xff];
  2354.                 if (xod4 & 0x0000ff00) dstdata[BL2] = paldata[(col4 >>  8) & 0xff];
  2355.                 if (xod4 & 0x000000ff) dstdata[BL3] = paldata[col4 & 0xff];
  2356.             }
  2357.             dstdata += 4;
  2358.         }
  2359.         srcdata = (UINT8 *)sd4;
  2360.         while (dstdata < end)
  2361.         {
  2362.             int col;
  2363.  
  2364.             col = srcdata[3];
  2365.             srcdata--;
  2366.             if (col != transpen) *dstdata = paldata[col];
  2367.             dstdata++;
  2368.         }
  2369.  
  2370.         srcdata += srcmodulo;
  2371.         dstdata += dstmodulo;
  2372.         srcheight--;
  2373.     }
  2374. })
  2375.  
  2376. DECLARE(blockmove_8toN_transpen_pri,(
  2377.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2378.         DATA_TYPE *dstdata,int dstmodulo,
  2379.         const UINT16 *paldata,int transpen,UINT8 *pridata,UINT32 pmask),
  2380. {
  2381.     DATA_TYPE *end;
  2382.     int trans4;
  2383.     UINT32 *sd4;
  2384.  
  2385.     pmask |= (1<<31);
  2386.  
  2387.     srcmodulo -= srcwidth;
  2388.     dstmodulo -= srcwidth;
  2389.  
  2390.     trans4 = transpen * 0x01010101;
  2391.  
  2392.     while (srcheight)
  2393.     {
  2394.         end = dstdata + srcwidth;
  2395.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2396.         {
  2397.             int col;
  2398.  
  2399.             col = *(srcdata++);
  2400.             if (col != transpen)
  2401.             {
  2402.                 if (((1 << *pridata) & pmask) == 0)
  2403.                     *dstdata = paldata[col];
  2404.                 *pridata = 31;
  2405.             }
  2406.             dstdata++;
  2407.             pridata++;
  2408.         }
  2409.         sd4 = (UINT32 *)srcdata;
  2410.         while (dstdata <= end - 4)
  2411.         {
  2412.             UINT32 col4;
  2413.  
  2414.             if ((col4 = *(sd4++)) != trans4)
  2415.             {
  2416.                 UINT32 xod4;
  2417.  
  2418.                 xod4 = col4 ^ trans4;
  2419.                 if (xod4 & 0x000000ff)
  2420.                 {
  2421.                     if (((1 << pridata[BL0]) & pmask) == 0)
  2422.                         dstdata[BL0] = paldata[(col4) & 0xff];
  2423.                     pridata[BL0] = 31;
  2424.                 }
  2425.                 if (xod4 & 0x0000ff00)
  2426.                 {
  2427.                     if (((1 << pridata[BL1]) & pmask) == 0)
  2428.                         dstdata[BL1] = paldata[(col4 >>  8) & 0xff];
  2429.                     pridata[BL1] = 31;
  2430.                 }
  2431.                 if (xod4 & 0x00ff0000)
  2432.                 {
  2433.                     if (((1 << pridata[BL2]) & pmask) == 0)
  2434.                         dstdata[BL2] = paldata[(col4 >> 16) & 0xff];
  2435.                     pridata[BL2] = 31;
  2436.                 }
  2437.                 if (xod4 & 0xff000000)
  2438.                 {
  2439.                     if (((1 << pridata[BL3]) & pmask) == 0)
  2440.                         dstdata[BL3] = paldata[col4 >> 24];
  2441.                     pridata[BL3] = 31;
  2442.                 }
  2443.             }
  2444.             dstdata += 4;
  2445.             pridata += 4;
  2446.         }
  2447.         srcdata = (UINT8 *)sd4;
  2448.         while (dstdata < end)
  2449.         {
  2450.             int col;
  2451.  
  2452.             col = *(srcdata++);
  2453.             if (col != transpen)
  2454.             {
  2455.                 if (((1 << *pridata) & pmask) == 0)
  2456.                     *dstdata = paldata[col];
  2457.                 *pridata = 31;
  2458.             }
  2459.             dstdata++;
  2460.             pridata++;
  2461.         }
  2462.  
  2463.         srcdata += srcmodulo;
  2464.         dstdata += dstmodulo;
  2465.         pridata += dstmodulo;
  2466.         srcheight--;
  2467.     }
  2468. })
  2469.  
  2470. DECLARE(blockmove_8toN_transpen_pri_flipx,(
  2471.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2472.         DATA_TYPE *dstdata,int dstmodulo,
  2473.         const UINT16 *paldata,int transpen,UINT8 *pridata,UINT32 pmask),
  2474. {
  2475.     DATA_TYPE *end;
  2476.     int trans4;
  2477.     UINT32 *sd4;
  2478.  
  2479.     pmask |= (1<<31);
  2480.  
  2481.     srcmodulo += srcwidth;
  2482.     dstmodulo -= srcwidth;
  2483.     //srcdata += srcwidth-1;
  2484.     srcdata -= 3;
  2485.  
  2486.     trans4 = transpen * 0x01010101;
  2487.  
  2488.     while (srcheight)
  2489.     {
  2490.         end = dstdata + srcwidth;
  2491.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2492.         {
  2493.             int col;
  2494.  
  2495.             col = srcdata[3];
  2496.             srcdata--;
  2497.             if (col != transpen)
  2498.             {
  2499.                 if (((1 << *pridata) & pmask) == 0)
  2500.                     *dstdata = paldata[col];
  2501.                 *pridata = 31;
  2502.             }
  2503.             dstdata++;
  2504.             pridata++;
  2505.         }
  2506.         sd4 = (UINT32 *)srcdata;
  2507.         while (dstdata <= end - 4)
  2508.         {
  2509.             UINT32 col4;
  2510.  
  2511.             if ((col4 = *(sd4--)) != trans4)
  2512.             {
  2513.                 UINT32 xod4;
  2514.  
  2515.                 xod4 = col4 ^ trans4;
  2516.                 if (xod4 & 0xff000000)
  2517.                 {
  2518.                     if (((1 << pridata[BL0]) & pmask) == 0)
  2519.                         dstdata[BL0] = paldata[col4 >> 24];
  2520.                     pridata[BL0] = 31;
  2521.                 }
  2522.                 if (xod4 & 0x00ff0000)
  2523.                 {
  2524.                     if (((1 << pridata[BL1]) & pmask) == 0)
  2525.                         dstdata[BL1] = paldata[(col4 >> 16) & 0xff];
  2526.                     pridata[BL1] = 31;
  2527.                 }
  2528.                 if (xod4 & 0x0000ff00)
  2529.                 {
  2530.                     if (((1 << pridata[BL2]) & pmask) == 0)
  2531.                         dstdata[BL2] = paldata[(col4 >>  8) & 0xff];
  2532.                     pridata[BL2] = 31;
  2533.                 }
  2534.                 if (xod4 & 0x000000ff)
  2535.                 {
  2536.                     if (((1 << pridata[BL3]) & pmask) == 0)
  2537.                         dstdata[BL3] = paldata[col4 & 0xff];
  2538.                     pridata[BL3] = 31;
  2539.                 }
  2540.             }
  2541.             dstdata += 4;
  2542.             pridata += 4;
  2543.         }
  2544.         srcdata = (UINT8 *)sd4;
  2545.         while (dstdata < end)
  2546.         {
  2547.             int col;
  2548.  
  2549.             col = srcdata[3];
  2550.             srcdata--;
  2551.             if (col != transpen)
  2552.             {
  2553.                 if (((1 << *pridata) & pmask) == 0)
  2554.                     *dstdata = paldata[col];
  2555.                 *pridata = 31;
  2556.             }
  2557.             dstdata++;
  2558.             pridata++;
  2559.         }
  2560.  
  2561.         srcdata += srcmodulo;
  2562.         dstdata += dstmodulo;
  2563.         pridata += dstmodulo;
  2564.         srcheight--;
  2565.     }
  2566. })
  2567.  
  2568. DECLARE(blockmove_8toN_transpen_raw,(
  2569.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2570.         DATA_TYPE *dstdata,int dstmodulo,
  2571.         unsigned int colorbase,int transpen),
  2572. {
  2573.     DATA_TYPE *end;
  2574.     int trans4;
  2575.     UINT32 *sd4;
  2576.  
  2577.     srcmodulo -= srcwidth;
  2578.     dstmodulo -= srcwidth;
  2579.  
  2580.     trans4 = transpen * 0x01010101;
  2581.  
  2582.     while (srcheight)
  2583.     {
  2584.         end = dstdata + srcwidth;
  2585.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2586.         {
  2587.             int col;
  2588.  
  2589.             col = *(srcdata++);
  2590.             if (col != transpen) *dstdata = colorbase + col;
  2591.             dstdata++;
  2592.         }
  2593.         sd4 = (UINT32 *)srcdata;
  2594.         while (dstdata <= end - 4)
  2595.         {
  2596.             UINT32 col4;
  2597.  
  2598.             if ((col4 = *(sd4++)) != trans4)
  2599.             {
  2600.                 UINT32 xod4;
  2601.  
  2602.                 xod4 = col4 ^ trans4;
  2603.                 if (xod4 & 0x000000ff) dstdata[BL0] = colorbase + ((col4) & 0xff);
  2604.                 if (xod4 & 0x0000ff00) dstdata[BL1] = colorbase + ((col4 >>  8) & 0xff);
  2605.                 if (xod4 & 0x00ff0000) dstdata[BL2] = colorbase + ((col4 >> 16) & 0xff);
  2606.                 if (xod4 & 0xff000000) dstdata[BL3] = colorbase + (col4 >> 24);
  2607.             }
  2608.             dstdata += 4;
  2609.         }
  2610.         srcdata = (UINT8 *)sd4;
  2611.         while (dstdata < end)
  2612.         {
  2613.             int col;
  2614.  
  2615.             col = *(srcdata++);
  2616.             if (col != transpen) *dstdata = colorbase + col;
  2617.             dstdata++;
  2618.         }
  2619.  
  2620.         srcdata += srcmodulo;
  2621.         dstdata += dstmodulo;
  2622.         srcheight--;
  2623.     }
  2624. })
  2625.  
  2626. DECLARE(blockmove_8toN_transpen_raw_flipx,(
  2627.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2628.         DATA_TYPE *dstdata,int dstmodulo,
  2629.         unsigned int colorbase, int transpen),
  2630. {
  2631.     DATA_TYPE *end;
  2632.     int trans4;
  2633.     UINT32 *sd4;
  2634.  
  2635.     srcmodulo += srcwidth;
  2636.     dstmodulo -= srcwidth;
  2637.     //srcdata += srcwidth-1;
  2638.     srcdata -= 3;
  2639.  
  2640.     trans4 = transpen * 0x01010101;
  2641.  
  2642.     while (srcheight)
  2643.     {
  2644.         end = dstdata + srcwidth;
  2645.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2646.         {
  2647.             int col;
  2648.  
  2649.             col = srcdata[3];
  2650.             srcdata--;
  2651.             if (col != transpen) *dstdata = colorbase + col;
  2652.             dstdata++;
  2653.         }
  2654.         sd4 = (UINT32 *)srcdata;
  2655.         while (dstdata <= end - 4)
  2656.         {
  2657.             UINT32 col4;
  2658.  
  2659.             if ((col4 = *(sd4--)) != trans4)
  2660.             {
  2661.                 UINT32 xod4;
  2662.  
  2663.                 xod4 = col4 ^ trans4;
  2664.                 if (xod4 & 0xff000000) dstdata[BL0] = colorbase + (col4 >> 24);
  2665.                 if (xod4 & 0x00ff0000) dstdata[BL1] = colorbase + ((col4 >> 16) & 0xff);
  2666.                 if (xod4 & 0x0000ff00) dstdata[BL2] = colorbase + ((col4 >>  8) & 0xff);
  2667.                 if (xod4 & 0x000000ff) dstdata[BL3] = colorbase + (col4 & 0xff);
  2668.             }
  2669.             dstdata += 4;
  2670.         }
  2671.         srcdata = (UINT8 *)sd4;
  2672.         while (dstdata < end)
  2673.         {
  2674.             int col;
  2675.  
  2676.             col = srcdata[3];
  2677.             srcdata--;
  2678.             if (col != transpen) *dstdata = colorbase + col;
  2679.             dstdata++;
  2680.         }
  2681.  
  2682.         srcdata += srcmodulo;
  2683.         dstdata += dstmodulo;
  2684.         srcheight--;
  2685.     }
  2686. })
  2687.  
  2688. #define PEN_IS_OPAQUE ((1<<col)&transmask) == 0
  2689.  
  2690. DECLARE(blockmove_8toN_transmask,(
  2691.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2692.         DATA_TYPE *dstdata,int dstmodulo,
  2693.         const UINT16 *paldata,int transmask),
  2694. {
  2695.     DATA_TYPE *end;
  2696.     UINT32 *sd4;
  2697.  
  2698.     srcmodulo -= srcwidth;
  2699.     dstmodulo -= srcwidth;
  2700.  
  2701.     while (srcheight)
  2702.     {
  2703.         end = dstdata + srcwidth;
  2704.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2705.         {
  2706.             int col;
  2707.  
  2708.             col = *(srcdata++);
  2709.             if (PEN_IS_OPAQUE) *dstdata = paldata[col];
  2710.             dstdata++;
  2711.         }
  2712.         sd4 = (UINT32 *)srcdata;
  2713.         while (dstdata <= end - 4)
  2714.         {
  2715.             int col;
  2716.             UINT32 col4;
  2717.  
  2718.             col4 = *(sd4++);
  2719.             col = (col4 >>  0) & 0xff;
  2720.             if (PEN_IS_OPAQUE) dstdata[BL0] = paldata[col];
  2721.             col = (col4 >>  8) & 0xff;
  2722.             if (PEN_IS_OPAQUE) dstdata[BL1] = paldata[col];
  2723.             col = (col4 >> 16) & 0xff;
  2724.             if (PEN_IS_OPAQUE) dstdata[BL2] = paldata[col];
  2725.             col = (col4 >> 24) & 0xff;
  2726.             if (PEN_IS_OPAQUE) dstdata[BL3] = paldata[col];
  2727.             dstdata += 4;
  2728.         }
  2729.         srcdata = (UINT8 *)sd4;
  2730.         while (dstdata < end)
  2731.         {
  2732.             int col;
  2733.  
  2734.             col = *(srcdata++);
  2735.             if (PEN_IS_OPAQUE) *dstdata = paldata[col];
  2736.             dstdata++;
  2737.         }
  2738.  
  2739.         srcdata += srcmodulo;
  2740.         dstdata += dstmodulo;
  2741.         srcheight--;
  2742.     }
  2743. })
  2744.  
  2745. DECLARE(blockmove_8toN_transmask_flipx,(
  2746.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2747.         DATA_TYPE *dstdata,int dstmodulo,
  2748.         const UINT16 *paldata,int transmask),
  2749. {
  2750.     DATA_TYPE *end;
  2751.     UINT32 *sd4;
  2752.  
  2753.     srcmodulo += srcwidth;
  2754.     dstmodulo -= srcwidth;
  2755.     //srcdata += srcwidth-1;
  2756.     srcdata -= 3;
  2757.  
  2758.     while (srcheight)
  2759.     {
  2760.         end = dstdata + srcwidth;
  2761.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2762.         {
  2763.             int col;
  2764.  
  2765.             col = srcdata[3];
  2766.             srcdata--;
  2767.             if (PEN_IS_OPAQUE) *dstdata = paldata[col];
  2768.             dstdata++;
  2769.         }
  2770.         sd4 = (UINT32 *)srcdata;
  2771.         while (dstdata <= end - 4)
  2772.         {
  2773.             int col;
  2774.             UINT32 col4;
  2775.  
  2776.             col4 = *(sd4--);
  2777.             col = (col4 >> 24) & 0xff;
  2778.             if (PEN_IS_OPAQUE) dstdata[BL0] = paldata[col];
  2779.             col = (col4 >> 16) & 0xff;
  2780.             if (PEN_IS_OPAQUE) dstdata[BL1] = paldata[col];
  2781.             col = (col4 >>  8) & 0xff;
  2782.             if (PEN_IS_OPAQUE) dstdata[BL2] = paldata[col];
  2783.             col = (col4 >>  0) & 0xff;
  2784.             if (PEN_IS_OPAQUE) dstdata[BL3] = paldata[col];
  2785.             dstdata += 4;
  2786.         }
  2787.         srcdata = (UINT8 *)sd4;
  2788.         while (dstdata < end)
  2789.         {
  2790.             int col;
  2791.  
  2792.             col = srcdata[3];
  2793.             srcdata--;
  2794.             if (PEN_IS_OPAQUE) *dstdata = paldata[col];
  2795.             dstdata++;
  2796.         }
  2797.  
  2798.         srcdata += srcmodulo;
  2799.         dstdata += dstmodulo;
  2800.         srcheight--;
  2801.     }
  2802. })
  2803.  
  2804. DECLARE(blockmove_8toN_transmask_pri,(
  2805.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2806.         DATA_TYPE *dstdata,int dstmodulo,
  2807.         const UINT16 *paldata,int transmask,UINT8 *pridata,UINT32 pmask),
  2808. {
  2809.     DATA_TYPE *end;
  2810.     UINT32 *sd4;
  2811.  
  2812.     pmask |= (1<<31);
  2813.  
  2814.     srcmodulo -= srcwidth;
  2815.     dstmodulo -= srcwidth;
  2816.  
  2817.     while (srcheight)
  2818.     {
  2819.         end = dstdata + srcwidth;
  2820.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2821.         {
  2822.             int col;
  2823.  
  2824.             col = *(srcdata++);
  2825.             if (PEN_IS_OPAQUE)
  2826.             {
  2827.                 if (((1 << *pridata) & pmask) == 0)
  2828.                     *dstdata = paldata[col];
  2829.                 *pridata = 31;
  2830.             }
  2831.             dstdata++;
  2832.             pridata++;
  2833.         }
  2834.         sd4 = (UINT32 *)srcdata;
  2835.         while (dstdata <= end - 4)
  2836.         {
  2837.             int col;
  2838.             UINT32 col4;
  2839.  
  2840.             col4 = *(sd4++);
  2841.             col = (col4 >>  0) & 0xff;
  2842.             if (PEN_IS_OPAQUE)
  2843.             {
  2844.                 if (((1 << pridata[BL0]) & pmask) == 0)
  2845.                     dstdata[BL0] = paldata[col];
  2846.                 pridata[BL0] = 31;
  2847.             }
  2848.             col = (col4 >>  8) & 0xff;
  2849.             if (PEN_IS_OPAQUE)
  2850.             {
  2851.                 if (((1 << pridata[BL1]) & pmask) == 0)
  2852.                     dstdata[BL1] = paldata[col];
  2853.                 pridata[BL1] = 31;
  2854.             }
  2855.             col = (col4 >> 16) & 0xff;
  2856.             if (PEN_IS_OPAQUE)
  2857.             {
  2858.                 if (((1 << pridata[BL2]) & pmask) == 0)
  2859.                     dstdata[BL2] = paldata[col];
  2860.                 pridata[BL2] = 31;
  2861.             }
  2862.             col = (col4 >> 24) & 0xff;
  2863.             if (PEN_IS_OPAQUE)
  2864.             {
  2865.                 if (((1 << pridata[BL3]) & pmask) == 0)
  2866.                     dstdata[BL3] = paldata[col];
  2867.                 pridata[BL3] = 31;
  2868.             }
  2869.             dstdata += 4;
  2870.             pridata += 4;
  2871.         }
  2872.         srcdata = (UINT8 *)sd4;
  2873.         while (dstdata < end)
  2874.         {
  2875.             int col;
  2876.  
  2877.             col = *(srcdata++);
  2878.             if (PEN_IS_OPAQUE)
  2879.             {
  2880.                 if (((1 << *pridata) & pmask) == 0)
  2881.                     *dstdata = paldata[col];
  2882.                 *pridata = 31;
  2883.             }
  2884.             dstdata++;
  2885.             pridata++;
  2886.         }
  2887.  
  2888.         srcdata += srcmodulo;
  2889.         dstdata += dstmodulo;
  2890.         pridata += dstmodulo;
  2891.         srcheight--;
  2892.     }
  2893. })
  2894.  
  2895. DECLARE(blockmove_8toN_transmask_pri_flipx,(
  2896.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2897.         DATA_TYPE *dstdata,int dstmodulo,
  2898.         const UINT16 *paldata,int transmask,UINT8 *pridata,UINT32 pmask),
  2899. {
  2900.     DATA_TYPE *end;
  2901.     UINT32 *sd4;
  2902.  
  2903.     pmask |= (1<<31);
  2904.  
  2905.     srcmodulo += srcwidth;
  2906.     dstmodulo -= srcwidth;
  2907.     //srcdata += srcwidth-1;
  2908.     srcdata -= 3;
  2909.  
  2910.     while (srcheight)
  2911.     {
  2912.         end = dstdata + srcwidth;
  2913.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  2914.         {
  2915.             int col;
  2916.  
  2917.             col = srcdata[3];
  2918.             srcdata--;
  2919.             if (PEN_IS_OPAQUE)
  2920.             {
  2921.                 if (((1 << *pridata) & pmask) == 0)
  2922.                     *dstdata = paldata[col];
  2923.                 *pridata = 31;
  2924.             }
  2925.             dstdata++;
  2926.             pridata++;
  2927.         }
  2928.         sd4 = (UINT32 *)srcdata;
  2929.         while (dstdata <= end - 4)
  2930.         {
  2931.             int col;
  2932.             UINT32 col4;
  2933.  
  2934.             col4 = *(sd4--);
  2935.             col = (col4 >> 24) & 0xff;
  2936.             if (PEN_IS_OPAQUE)
  2937.             {
  2938.                 if (((1 << pridata[BL0]) & pmask) == 0)
  2939.                     dstdata[BL0] = paldata[col];
  2940.                 pridata[BL0] = 31;
  2941.             }
  2942.             col = (col4 >> 16) & 0xff;
  2943.             if (PEN_IS_OPAQUE)
  2944.             {
  2945.                 if (((1 << pridata[BL1]) & pmask) == 0)
  2946.                     dstdata[BL1] = paldata[col];
  2947.                 pridata[BL1] = 31;
  2948.             }
  2949.             col = (col4 >>  8) & 0xff;
  2950.             if (PEN_IS_OPAQUE)
  2951.             {
  2952.                 if (((1 << pridata[BL2]) & pmask) == 0)
  2953.                     dstdata[BL2] = paldata[col];
  2954.                 pridata[BL2] = 31;
  2955.             }
  2956.             col = (col4 >>  0) & 0xff;
  2957.             if (PEN_IS_OPAQUE)
  2958.             {
  2959.                 if (((1 << pridata[BL3]) & pmask) == 0)
  2960.                     dstdata[BL3] = paldata[col];
  2961.                 pridata[BL3] = 31;
  2962.             }
  2963.             dstdata += 4;
  2964.             pridata += 4;
  2965.         }
  2966.         srcdata = (UINT8 *)sd4;
  2967.         while (dstdata < end)
  2968.         {
  2969.             int col;
  2970.  
  2971.             col = srcdata[3];
  2972.             srcdata--;
  2973.             if (PEN_IS_OPAQUE)
  2974.             {
  2975.                 if (((1 << *pridata) & pmask) == 0)
  2976.                     *dstdata = paldata[col];
  2977.                 *pridata = 31;
  2978.             }
  2979.             dstdata++;
  2980.             pridata++;
  2981.         }
  2982.  
  2983.         srcdata += srcmodulo;
  2984.         dstdata += dstmodulo;
  2985.         pridata += dstmodulo;
  2986.         srcheight--;
  2987.     }
  2988. })
  2989.  
  2990. DECLARE(blockmove_8toN_transmask_raw,(
  2991.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  2992.         DATA_TYPE *dstdata,int dstmodulo,
  2993.         unsigned int colorbase,int transmask),
  2994. {
  2995.     DATA_TYPE *end;
  2996.     UINT32 *sd4;
  2997.  
  2998.     srcmodulo -= srcwidth;
  2999.     dstmodulo -= srcwidth;
  3000.  
  3001.     while (srcheight)
  3002.     {
  3003.         end = dstdata + srcwidth;
  3004.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  3005.         {
  3006.             int col;
  3007.  
  3008.             col = *(srcdata++);
  3009.             if (PEN_IS_OPAQUE) *dstdata = colorbase + col;
  3010.             dstdata++;
  3011.         }
  3012.         sd4 = (UINT32 *)srcdata;
  3013.         while (dstdata <= end - 4)
  3014.         {
  3015.             int col;
  3016.             UINT32 col4;
  3017.  
  3018.             col4 = *(sd4++);
  3019.             col = (col4 >>  0) & 0xff;
  3020.             if (PEN_IS_OPAQUE) dstdata[BL0] = colorbase + col;
  3021.             col = (col4 >>  8) & 0xff;
  3022.             if (PEN_IS_OPAQUE) dstdata[BL1] = colorbase + col;
  3023.             col = (col4 >> 16) & 0xff;
  3024.             if (PEN_IS_OPAQUE) dstdata[BL2] = colorbase + col;
  3025.             col = (col4 >> 24) & 0xff;
  3026.             if (PEN_IS_OPAQUE) dstdata[BL3] = colorbase + col;
  3027.             dstdata += 4;
  3028.         }
  3029.         srcdata = (UINT8 *)sd4;
  3030.         while (dstdata < end)
  3031.         {
  3032.             int col;
  3033.  
  3034.             col = *(srcdata++);
  3035.             if (PEN_IS_OPAQUE) *dstdata = colorbase + col;
  3036.             dstdata++;
  3037.         }
  3038.  
  3039.         srcdata += srcmodulo;
  3040.         dstdata += dstmodulo;
  3041.         srcheight--;
  3042.     }
  3043. })
  3044.  
  3045. DECLARE(blockmove_8toN_transmask_raw_flipx,(
  3046.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3047.         DATA_TYPE *dstdata,int dstmodulo,
  3048.         unsigned int colorbase,int transmask),
  3049. {
  3050.     DATA_TYPE *end;
  3051.     UINT32 *sd4;
  3052.  
  3053.     srcmodulo += srcwidth;
  3054.     dstmodulo -= srcwidth;
  3055.     //srcdata += srcwidth-1;
  3056.     srcdata -= 3;
  3057.  
  3058.     while (srcheight)
  3059.     {
  3060.         end = dstdata + srcwidth;
  3061.         while (((long)srcdata & 3) && dstdata < end)    /* longword align */
  3062.         {
  3063.             int col;
  3064.  
  3065.             col = srcdata[3];
  3066.             srcdata--;
  3067.             if (PEN_IS_OPAQUE) *dstdata = colorbase + col;
  3068.             dstdata++;
  3069.         }
  3070.         sd4 = (UINT32 *)srcdata;
  3071.         while (dstdata <= end - 4)
  3072.         {
  3073.             int col;
  3074.             UINT32 col4;
  3075.  
  3076.             col4 = *(sd4--);
  3077.             col = (col4 >> 24) & 0xff;
  3078.             if (PEN_IS_OPAQUE) dstdata[BL0] = colorbase + col;
  3079.             col = (col4 >> 16) & 0xff;
  3080.             if (PEN_IS_OPAQUE) dstdata[BL1] = colorbase + col;
  3081.             col = (col4 >>  8) & 0xff;
  3082.             if (PEN_IS_OPAQUE) dstdata[BL2] = colorbase + col;
  3083.             col = (col4 >>  0) & 0xff;
  3084.             if (PEN_IS_OPAQUE) dstdata[BL3] = colorbase + col;
  3085.             dstdata += 4;
  3086.         }
  3087.         srcdata = (UINT8 *)sd4;
  3088.         while (dstdata < end)
  3089.         {
  3090.             int col;
  3091.  
  3092.             col = srcdata[3];
  3093.             srcdata--;
  3094.             if (PEN_IS_OPAQUE) *dstdata = colorbase + col;
  3095.             dstdata++;
  3096.         }
  3097.  
  3098.         srcdata += srcmodulo;
  3099.         dstdata += dstmodulo;
  3100.         srcheight--;
  3101.     }
  3102. })
  3103.  
  3104.  
  3105. DECLARE(blockmove_8toN_transcolor,(
  3106.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3107.         DATA_TYPE *dstdata,int dstmodulo,
  3108.         const UINT16 *paldata,int transcolor),
  3109. {
  3110.     DATA_TYPE *end;
  3111.     const UINT16 *lookupdata = Machine->game_colortable + (paldata - Machine->remapped_colortable);
  3112.  
  3113.     srcmodulo -= srcwidth;
  3114.     dstmodulo -= srcwidth;
  3115.  
  3116.     while (srcheight)
  3117.     {
  3118.         end = dstdata + srcwidth;
  3119.         while (dstdata < end)
  3120.         {
  3121.             if (lookupdata[*srcdata] != transcolor) *dstdata = paldata[*srcdata];
  3122.             srcdata++;
  3123.             dstdata++;
  3124.         }
  3125.  
  3126.         srcdata += srcmodulo;
  3127.         dstdata += dstmodulo;
  3128.         srcheight--;
  3129.     }
  3130. })
  3131.  
  3132. DECLARE(blockmove_8toN_transcolor_flipx,(
  3133.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3134.         DATA_TYPE *dstdata,int dstmodulo,
  3135.         const UINT16 *paldata,int transcolor),
  3136. {
  3137.     DATA_TYPE *end;
  3138.     const UINT16 *lookupdata = Machine->game_colortable + (paldata - Machine->remapped_colortable);
  3139.  
  3140.     srcmodulo += srcwidth;
  3141.     dstmodulo -= srcwidth;
  3142.     //srcdata += srcwidth-1;
  3143.  
  3144.     while (srcheight)
  3145.     {
  3146.         end = dstdata + srcwidth;
  3147.         while (dstdata < end)
  3148.         {
  3149.             if (lookupdata[*srcdata] != transcolor) *dstdata = paldata[*srcdata];
  3150.             srcdata--;
  3151.             dstdata++;
  3152.         }
  3153.  
  3154.         srcdata += srcmodulo;
  3155.         dstdata += dstmodulo;
  3156.         srcheight--;
  3157.     }
  3158. })
  3159.  
  3160. DECLARE(blockmove_8toN_transcolor_pri,(
  3161.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3162.         DATA_TYPE *dstdata,int dstmodulo,
  3163.         const UINT16 *paldata,int transcolor,UINT8 *pridata,UINT32 pmask),
  3164. {
  3165.     DATA_TYPE *end;
  3166.     const UINT16 *lookupdata = Machine->game_colortable + (paldata - Machine->remapped_colortable);
  3167.  
  3168.     pmask |= (1<<31);
  3169.  
  3170.     srcmodulo -= srcwidth;
  3171.     dstmodulo -= srcwidth;
  3172.  
  3173.     while (srcheight)
  3174.     {
  3175.         end = dstdata + srcwidth;
  3176.         while (dstdata < end)
  3177.         {
  3178.             if (lookupdata[*srcdata] != transcolor)
  3179.             {
  3180.                 if (((1 << *pridata) & pmask) == 0)
  3181.                     *dstdata = paldata[*srcdata];
  3182.                 *pridata = 31;
  3183.             }
  3184.             srcdata++;
  3185.             dstdata++;
  3186.             pridata++;
  3187.         }
  3188.  
  3189.         srcdata += srcmodulo;
  3190.         dstdata += dstmodulo;
  3191.         pridata += dstmodulo;
  3192.         srcheight--;
  3193.     }
  3194. })
  3195.  
  3196. DECLARE(blockmove_8toN_transcolor_pri_flipx,(
  3197.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3198.         DATA_TYPE *dstdata,int dstmodulo,
  3199.         const UINT16 *paldata,int transcolor,UINT8 *pridata,UINT32 pmask),
  3200. {
  3201.     DATA_TYPE *end;
  3202.     const UINT16 *lookupdata = Machine->game_colortable + (paldata - Machine->remapped_colortable);
  3203.  
  3204.     pmask |= (1<<31);
  3205.  
  3206.     srcmodulo += srcwidth;
  3207.     dstmodulo -= srcwidth;
  3208.     //srcdata += srcwidth-1;
  3209.  
  3210.     while (srcheight)
  3211.     {
  3212.         end = dstdata + srcwidth;
  3213.         while (dstdata < end)
  3214.         {
  3215.             if (lookupdata[*srcdata] != transcolor)
  3216.             {
  3217.                 if (((1 << *pridata) & pmask) == 0)
  3218.                     *dstdata = paldata[*srcdata];
  3219.                 *pridata = 31;
  3220.             }
  3221.             srcdata--;
  3222.             dstdata++;
  3223.             pridata++;
  3224.         }
  3225.  
  3226.         srcdata += srcmodulo;
  3227.         dstdata += dstmodulo;
  3228.         pridata += dstmodulo;
  3229.         srcheight--;
  3230.     }
  3231. })
  3232.  
  3233.  
  3234. DECLARE(blockmove_8toN_transthrough,(
  3235.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3236.         DATA_TYPE *dstdata,int dstmodulo,
  3237.         const UINT16 *paldata,int transcolor),
  3238. {
  3239.     DATA_TYPE *end;
  3240.  
  3241.     srcmodulo -= srcwidth;
  3242.     dstmodulo -= srcwidth;
  3243.  
  3244.     while (srcheight)
  3245.     {
  3246.         end = dstdata + srcwidth;
  3247.         while (dstdata < end)
  3248.         {
  3249.             if (*dstdata == transcolor) *dstdata = paldata[*srcdata];
  3250.             srcdata++;
  3251.             dstdata++;
  3252.         }
  3253.  
  3254.         srcdata += srcmodulo;
  3255.         dstdata += dstmodulo;
  3256.         srcheight--;
  3257.     }
  3258. })
  3259.  
  3260. DECLARE(blockmove_8toN_transthrough_flipx,(
  3261.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3262.         DATA_TYPE *dstdata,int dstmodulo,
  3263.         const UINT16 *paldata,int transcolor),
  3264. {
  3265.     DATA_TYPE *end;
  3266.  
  3267.     srcmodulo += srcwidth;
  3268.     dstmodulo -= srcwidth;
  3269.     //srcdata += srcwidth-1;
  3270.  
  3271.     while (srcheight)
  3272.     {
  3273.         end = dstdata + srcwidth;
  3274.         while (dstdata < end)
  3275.         {
  3276.             if (*dstdata == transcolor) *dstdata = paldata[*srcdata];
  3277.             srcdata--;
  3278.             dstdata++;
  3279.         }
  3280.  
  3281.         srcdata += srcmodulo;
  3282.         dstdata += dstmodulo;
  3283.         srcheight--;
  3284.     }
  3285. })
  3286.  
  3287. DECLARE(blockmove_8toN_transthrough_raw,(
  3288.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3289.         DATA_TYPE *dstdata,int dstmodulo,
  3290.         unsigned int colorbase,int transcolor),
  3291. {
  3292.     DATA_TYPE *end;
  3293.  
  3294.     srcmodulo -= srcwidth;
  3295.     dstmodulo -= srcwidth;
  3296.  
  3297.     while (srcheight)
  3298.     {
  3299.         end = dstdata + srcwidth;
  3300.         while (dstdata < end)
  3301.         {
  3302.             if (*dstdata == transcolor) *dstdata = colorbase + *srcdata;
  3303.             srcdata++;
  3304.             dstdata++;
  3305.         }
  3306.  
  3307.         srcdata += srcmodulo;
  3308.         dstdata += dstmodulo;
  3309.         srcheight--;
  3310.     }
  3311. })
  3312.  
  3313. DECLARE(blockmove_8toN_transthrough_raw_flipx,(
  3314.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3315.         DATA_TYPE *dstdata,int dstmodulo,
  3316.         unsigned int colorbase,int transcolor),
  3317. {
  3318.     DATA_TYPE *end;
  3319.  
  3320.     srcmodulo += srcwidth;
  3321.     dstmodulo -= srcwidth;
  3322.     //srcdata += srcwidth-1;
  3323.  
  3324.     while (srcheight)
  3325.     {
  3326.         end = dstdata + srcwidth;
  3327.         while (dstdata < end)
  3328.         {
  3329.             if (*dstdata == transcolor) *dstdata = colorbase + *srcdata;
  3330.             srcdata--;
  3331.             dstdata++;
  3332.         }
  3333.  
  3334.         srcdata += srcmodulo;
  3335.         dstdata += dstmodulo;
  3336.         srcheight--;
  3337.     }
  3338. })
  3339.  
  3340. DECLARE(blockmove_8toN_pen_table,(
  3341.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3342.         DATA_TYPE *dstdata,int dstmodulo,
  3343.         const UINT16 *paldata,int transcolor),
  3344. {
  3345.     DATA_TYPE *end;
  3346.  
  3347.     srcmodulo -= srcwidth;
  3348.     dstmodulo -= srcwidth;
  3349.  
  3350.     while (srcheight)
  3351.     {
  3352.         end = dstdata + srcwidth;
  3353.         while (dstdata < end)
  3354.         {
  3355.             int col;
  3356.  
  3357.             col = *(srcdata++);
  3358.             if (col != transcolor)
  3359.             {
  3360.                 switch(gfx_drawmode_table[col])
  3361.                 {
  3362.                 case DRAWMODE_SOURCE:
  3363.                     *dstdata = paldata[col];
  3364.                     break;
  3365.                 case DRAWMODE_SHADOW:
  3366.                     *dstdata = palette_shadow_table[*dstdata];
  3367.                     break;
  3368.                 case DRAWMODE_HIGHLIGHT:
  3369.                     *dstdata = palette_highlight_table[*dstdata];
  3370.                     break;
  3371.                 }
  3372.             }
  3373.             dstdata++;
  3374.         }
  3375.  
  3376.         srcdata += srcmodulo;
  3377.         dstdata += dstmodulo;
  3378.         srcheight--;
  3379.     }
  3380. })
  3381.  
  3382. DECLARE(blockmove_8toN_pen_table_flipx,(
  3383.         const UINT8 *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3384.         DATA_TYPE *dstdata,int dstmodulo,
  3385.         const UINT16 *paldata,int transcolor),
  3386. {
  3387.     DATA_TYPE *end;
  3388.  
  3389.     srcmodulo += srcwidth;
  3390.     dstmodulo -= srcwidth;
  3391.     //srcdata += srcwidth-1;
  3392.  
  3393.     while (srcheight)
  3394.     {
  3395.         end = dstdata + srcwidth;
  3396.         while (dstdata < end)
  3397.         {
  3398.             int col;
  3399.  
  3400.             col = *(srcdata--);
  3401.             if (col != transcolor)
  3402.             {
  3403.                 switch(gfx_drawmode_table[col])
  3404.                 {
  3405.                 case DRAWMODE_SOURCE:
  3406.                     *dstdata = paldata[col];
  3407.                     break;
  3408.                 case DRAWMODE_SHADOW:
  3409.                     *dstdata = palette_shadow_table[*dstdata];
  3410.                     break;
  3411.                 case DRAWMODE_HIGHLIGHT:
  3412.                     *dstdata = palette_highlight_table[*dstdata];
  3413.                     break;
  3414.                 }
  3415.             }
  3416.             dstdata++;
  3417.         }
  3418.  
  3419.         srcdata += srcmodulo;
  3420.         dstdata += dstmodulo;
  3421.         srcheight--;
  3422.     }
  3423. })
  3424.  
  3425. DECLARE(blockmove_NtoN_opaque_noremap,(
  3426.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3427.         DATA_TYPE *dstdata,int dstmodulo),
  3428. {
  3429.     while (srcheight)
  3430.     {
  3431.         memcpy(dstdata,srcdata,srcwidth * sizeof(DATA_TYPE));
  3432.         srcdata += srcmodulo;
  3433.         dstdata += dstmodulo;
  3434.         srcheight--;
  3435.     }
  3436. })
  3437.  
  3438. DECLARE(blockmove_NtoN_opaque_noremap_flipx,(
  3439.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3440.         DATA_TYPE *dstdata,int dstmodulo),
  3441. {
  3442.     DATA_TYPE *end;
  3443.  
  3444.     srcmodulo += srcwidth;
  3445.     dstmodulo -= srcwidth;
  3446.     //srcdata += srcwidth-1;
  3447.  
  3448.     while (srcheight)
  3449.     {
  3450.         end = dstdata + srcwidth;
  3451.         while (dstdata <= end - 8)
  3452.         {
  3453.             srcdata -= 8;
  3454.             dstdata[0] = srcdata[8];
  3455.             dstdata[1] = srcdata[7];
  3456.             dstdata[2] = srcdata[6];
  3457.             dstdata[3] = srcdata[5];
  3458.             dstdata[4] = srcdata[4];
  3459.             dstdata[5] = srcdata[3];
  3460.             dstdata[6] = srcdata[2];
  3461.             dstdata[7] = srcdata[1];
  3462.             dstdata += 8;
  3463.         }
  3464.         while (dstdata < end)
  3465.             *(dstdata++) = *(srcdata--);
  3466.  
  3467.         srcdata += srcmodulo;
  3468.         dstdata += dstmodulo;
  3469.         srcheight--;
  3470.     }
  3471. })
  3472.  
  3473. DECLARE(blockmove_NtoN_opaque_remap,(
  3474.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3475.         DATA_TYPE *dstdata,int dstmodulo,
  3476.         const UINT16 *paldata),
  3477. {
  3478.     DATA_TYPE *end;
  3479.  
  3480.     srcmodulo -= srcwidth;
  3481.     dstmodulo -= srcwidth;
  3482.  
  3483.     while (srcheight)
  3484.     {
  3485.         end = dstdata + srcwidth;
  3486.         while (dstdata <= end - 8)
  3487.         {
  3488.             dstdata[0] = paldata[srcdata[0]];
  3489.             dstdata[1] = paldata[srcdata[1]];
  3490.             dstdata[2] = paldata[srcdata[2]];
  3491.             dstdata[3] = paldata[srcdata[3]];
  3492.             dstdata[4] = paldata[srcdata[4]];
  3493.             dstdata[5] = paldata[srcdata[5]];
  3494.             dstdata[6] = paldata[srcdata[6]];
  3495.             dstdata[7] = paldata[srcdata[7]];
  3496.             dstdata += 8;
  3497.             srcdata += 8;
  3498.         }
  3499.         while (dstdata < end)
  3500.             *(dstdata++) = paldata[*(srcdata++)];
  3501.  
  3502.         srcdata += srcmodulo;
  3503.         dstdata += dstmodulo;
  3504.         srcheight--;
  3505.     }
  3506. })
  3507.  
  3508. DECLARE(blockmove_NtoN_opaque_remap_flipx,(
  3509.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3510.         DATA_TYPE *dstdata,int dstmodulo,
  3511.         const UINT16 *paldata),
  3512. {
  3513.     DATA_TYPE *end;
  3514.  
  3515.     srcmodulo += srcwidth;
  3516.     dstmodulo -= srcwidth;
  3517.     //srcdata += srcwidth-1;
  3518.  
  3519.     while (srcheight)
  3520.     {
  3521.         end = dstdata + srcwidth;
  3522.         while (dstdata <= end - 8)
  3523.         {
  3524.             srcdata -= 8;
  3525.             dstdata[0] = paldata[srcdata[8]];
  3526.             dstdata[1] = paldata[srcdata[7]];
  3527.             dstdata[2] = paldata[srcdata[6]];
  3528.             dstdata[3] = paldata[srcdata[5]];
  3529.             dstdata[4] = paldata[srcdata[4]];
  3530.             dstdata[5] = paldata[srcdata[3]];
  3531.             dstdata[6] = paldata[srcdata[2]];
  3532.             dstdata[7] = paldata[srcdata[1]];
  3533.             dstdata += 8;
  3534.         }
  3535.         while (dstdata < end)
  3536.             *(dstdata++) = paldata[*(srcdata--)];
  3537.  
  3538.         srcdata += srcmodulo;
  3539.         dstdata += dstmodulo;
  3540.         srcheight--;
  3541.     }
  3542. })
  3543.  
  3544.  
  3545. DECLARE(blockmove_NtoN_transthrough_noremap,(
  3546.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3547.         DATA_TYPE *dstdata,int dstmodulo,
  3548.         int transcolor),
  3549. {
  3550.     DATA_TYPE *end;
  3551.  
  3552.     srcmodulo -= srcwidth;
  3553.     dstmodulo -= srcwidth;
  3554.  
  3555.     while (srcheight)
  3556.     {
  3557.         end = dstdata + srcwidth;
  3558.         while (dstdata < end)
  3559.         {
  3560.             if (*dstdata == transcolor) *dstdata = *srcdata;
  3561.             srcdata++;
  3562.             dstdata++;
  3563.         }
  3564.  
  3565.         srcdata += srcmodulo;
  3566.         dstdata += dstmodulo;
  3567.         srcheight--;
  3568.     }
  3569. })
  3570.  
  3571. DECLARE(blockmove_NtoN_transthrough_noremap_flipx,(
  3572.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3573.         DATA_TYPE *dstdata,int dstmodulo,
  3574.         int transcolor),
  3575. {
  3576.     DATA_TYPE *end;
  3577.  
  3578.     srcmodulo += srcwidth;
  3579.     dstmodulo -= srcwidth;
  3580.     //srcdata += srcwidth-1;
  3581.  
  3582.     while (srcheight)
  3583.     {
  3584.         end = dstdata + srcwidth;
  3585.         while (dstdata < end)
  3586.         {
  3587.             if (*dstdata == transcolor) *dstdata = *srcdata;
  3588.             srcdata--;
  3589.             dstdata++;
  3590.         }
  3591.  
  3592.         srcdata += srcmodulo;
  3593.         dstdata += dstmodulo;
  3594.         srcheight--;
  3595.     }
  3596. })
  3597.  
  3598. DECLARE(blockmove_NtoN_blend_noremap,(
  3599.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3600.         DATA_TYPE *dstdata,int dstmodulo,
  3601.         int srcshift),
  3602. {
  3603.     DATA_TYPE *end;
  3604.  
  3605.     srcmodulo -= srcwidth;
  3606.     dstmodulo -= srcwidth;
  3607.  
  3608.     while (srcheight)
  3609.     {
  3610.         end = dstdata + srcwidth;
  3611.         while (dstdata <= end - 8)
  3612.         {
  3613.             dstdata[0] |= srcdata[0] << srcshift;
  3614.             dstdata[1] |= srcdata[1] << srcshift;
  3615.             dstdata[2] |= srcdata[2] << srcshift;
  3616.             dstdata[3] |= srcdata[3] << srcshift;
  3617.             dstdata[4] |= srcdata[4] << srcshift;
  3618.             dstdata[5] |= srcdata[5] << srcshift;
  3619.             dstdata[6] |= srcdata[6] << srcshift;
  3620.             dstdata[7] |= srcdata[7] << srcshift;
  3621.             dstdata += 8;
  3622.             srcdata += 8;
  3623.         }
  3624.         while (dstdata < end)
  3625.             *(dstdata++) |= *(srcdata++) << srcshift;
  3626.  
  3627.         srcdata += srcmodulo;
  3628.         dstdata += dstmodulo;
  3629.         srcheight--;
  3630.     }
  3631. })
  3632.  
  3633. DECLARE(blockmove_NtoN_blend_noremap_flipx,(
  3634.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3635.         DATA_TYPE *dstdata,int dstmodulo,
  3636.         int srcshift),
  3637. {
  3638.     DATA_TYPE *end;
  3639.  
  3640.     srcmodulo += srcwidth;
  3641.     dstmodulo -= srcwidth;
  3642.     //srcdata += srcwidth-1;
  3643.  
  3644.     while (srcheight)
  3645.     {
  3646.         end = dstdata + srcwidth;
  3647.         while (dstdata <= end - 8)
  3648.         {
  3649.             srcdata -= 8;
  3650.             dstdata[0] |= srcdata[8] << srcshift;
  3651.             dstdata[1] |= srcdata[7] << srcshift;
  3652.             dstdata[2] |= srcdata[6] << srcshift;
  3653.             dstdata[3] |= srcdata[5] << srcshift;
  3654.             dstdata[4] |= srcdata[4] << srcshift;
  3655.             dstdata[5] |= srcdata[3] << srcshift;
  3656.             dstdata[6] |= srcdata[2] << srcshift;
  3657.             dstdata[7] |= srcdata[1] << srcshift;
  3658.             dstdata += 8;
  3659.         }
  3660.         while (dstdata < end)
  3661.             *(dstdata++) |= *(srcdata--) << srcshift;
  3662.  
  3663.         srcdata += srcmodulo;
  3664.         dstdata += dstmodulo;
  3665.         srcheight--;
  3666.     }
  3667. })
  3668.  
  3669. DECLARE(blockmove_NtoN_blend_remap,(
  3670.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3671.         DATA_TYPE *dstdata,int dstmodulo,
  3672.         const UINT16 *paldata,int srcshift),
  3673. {
  3674.     DATA_TYPE *end;
  3675.  
  3676.     srcmodulo -= srcwidth;
  3677.     dstmodulo -= srcwidth;
  3678.  
  3679.     while (srcheight)
  3680.     {
  3681.         end = dstdata + srcwidth;
  3682.         while (dstdata <= end - 8)
  3683.         {
  3684.             dstdata[0] = paldata[dstdata[0] | (srcdata[0] << srcshift)];
  3685.             dstdata[1] = paldata[dstdata[1] | (srcdata[1] << srcshift)];
  3686.             dstdata[2] = paldata[dstdata[2] | (srcdata[2] << srcshift)];
  3687.             dstdata[3] = paldata[dstdata[3] | (srcdata[3] << srcshift)];
  3688.             dstdata[4] = paldata[dstdata[4] | (srcdata[4] << srcshift)];
  3689.             dstdata[5] = paldata[dstdata[5] | (srcdata[5] << srcshift)];
  3690.             dstdata[6] = paldata[dstdata[6] | (srcdata[6] << srcshift)];
  3691.             dstdata[7] = paldata[dstdata[7] | (srcdata[7] << srcshift)];
  3692.             dstdata += 8;
  3693.             srcdata += 8;
  3694.         }
  3695.         while (dstdata < end)
  3696.         {
  3697.             *dstdata = paldata[*dstdata | (*(srcdata++) << srcshift)];
  3698.             dstdata++;
  3699.         }
  3700.  
  3701.         srcdata += srcmodulo;
  3702.         dstdata += dstmodulo;
  3703.         srcheight--;
  3704.     }
  3705. })
  3706.  
  3707. DECLARE(blockmove_NtoN_blend_remap_flipx,(
  3708.         const DATA_TYPE *srcdata,int srcwidth,int srcheight,int srcmodulo,
  3709.         DATA_TYPE *dstdata,int dstmodulo,
  3710.         const UINT16 *paldata,int srcshift),
  3711. {
  3712.     DATA_TYPE *end;
  3713.  
  3714.     srcmodulo += srcwidth;
  3715.     dstmodulo -= srcwidth;
  3716.     //srcdata += srcwidth-1;
  3717.  
  3718.     while (srcheight)
  3719.     {
  3720.         end = dstdata + srcwidth;
  3721.         while (dstdata <= end - 8)
  3722.         {
  3723.             srcdata -= 8;
  3724.             dstdata[0] = paldata[dstdata[0] | (srcdata[8] << srcshift)];
  3725.             dstdata[1] = paldata[dstdata[1] | (srcdata[7] << srcshift)];
  3726.             dstdata[2] = paldata[dstdata[2] | (srcdata[6] << srcshift)];
  3727.             dstdata[3] = paldata[dstdata[3] | (srcdata[5] << srcshift)];
  3728.             dstdata[4] = paldata[dstdata[4] | (srcdata[4] << srcshift)];
  3729.             dstdata[5] = paldata[dstdata[5] | (srcdata[3] << srcshift)];
  3730.             dstdata[6] = paldata[dstdata[6] | (srcdata[2] << srcshift)];
  3731.             dstdata[7] = paldata[dstdata[7] | (srcdata[1] << srcshift)];
  3732.             dstdata += 8;
  3733.         }
  3734.         while (dstdata < end)
  3735.         {
  3736.             *dstdata = paldata[*dstdata | (*(srcdata--) << srcshift)];
  3737.             dstdata++;
  3738.         }
  3739.  
  3740.         srcdata += srcmodulo;
  3741.         dstdata += dstmodulo;
  3742.         srcheight--;
  3743.     }
  3744. })
  3745.  
  3746.  
  3747. DECLARE(drawgfx_core,(
  3748.         struct osd_bitmap *dest,const struct GfxElement *gfx,
  3749.         unsigned int code,unsigned int color,int flipx,int flipy,int sx,int sy,
  3750.         const struct rectangle *clip,int transparency,int transparent_color,
  3751.         struct osd_bitmap *pri_buffer,UINT32 pri_mask),
  3752. {
  3753.     int ox;
  3754.     int oy;
  3755.     int ex;
  3756.     int ey;
  3757.  
  3758.  
  3759.     /* check bounds */
  3760.     ox = sx;
  3761.     oy = sy;
  3762.  
  3763.     ex = sx + gfx->width-1;
  3764.     if (sx < 0) sx = 0;
  3765.     if (clip && sx < clip->min_x) sx = clip->min_x;
  3766.     if (ex >= dest->width) ex = dest->width-1;
  3767.     if (clip && ex > clip->max_x) ex = clip->max_x;
  3768.     if (sx > ex) return;
  3769.  
  3770.     ey = sy + gfx->height-1;
  3771.     if (sy < 0) sy = 0;
  3772.     if (clip && sy < clip->min_y) sy = clip->min_y;
  3773.     if (ey >= dest->height) ey = dest->height-1;
  3774.     if (clip && ey > clip->max_y) ey = clip->max_y;
  3775.     if (sy > ey) return;
  3776.  
  3777.     osd_mark_dirty (sx,sy,ex,ey,0);    /* ASG 971011 */
  3778.  
  3779.     {
  3780.         UINT8 *sd = gfx->gfxdata + code * gfx->char_modulo;        /* source data */
  3781.         int sw = ex-sx+1;                                        /* source width */
  3782.         int sh = ey-sy+1;                                        /* source height */
  3783.         int sm = gfx->line_modulo;                                /* source modulo */
  3784.         DATA_TYPE *dd = ((DATA_TYPE *)dest->line[sy]) + sx;        /* dest data */
  3785.         int dm = ((DATA_TYPE *)dest->line[1])-((DATA_TYPE *)dest->line[0]);    /* dest modulo */
  3786.         const UINT16 *paldata = &gfx->colortable[gfx->color_granularity * color];
  3787.         UINT8 *pribuf = (pri_buffer) ? pri_buffer->line[sy] + sx : NULL;
  3788.  
  3789.         if (flipx)
  3790.         {
  3791.             //if ((sx-ox) == 0) sd += gfx->width - sw;
  3792.             sd += gfx->width -1 -(sx-ox);
  3793.         }
  3794.         else
  3795.             sd += (sx-ox);
  3796.  
  3797.         if (flipy)
  3798.         {
  3799.             //if ((sy-oy) == 0) sd += sm * (gfx->height - sh);
  3800.             //dd += dm * (sh - 1);
  3801.             //dm = -dm;
  3802.             sd += sm * (gfx->height -1 -(sy-oy));
  3803.             sm = -sm;
  3804.         }
  3805.         else
  3806.             sd += sm * (sy-oy);
  3807.  
  3808.         switch (transparency)
  3809.         {
  3810.             case TRANSPARENCY_NONE:
  3811.                 if (pribuf)
  3812.                     BLOCKMOVE(8toN_opaque_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
  3813.                 else
  3814.                     BLOCKMOVE(8toN_opaque,flipx,(sd,sw,sh,sm,dd,dm,paldata));
  3815.                 break;
  3816.  
  3817.             case TRANSPARENCY_PEN:
  3818.                 if (pribuf)
  3819.                     BLOCKMOVE(8toN_transpen_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color,pribuf,pri_mask));
  3820.                 else
  3821.                     BLOCKMOVE(8toN_transpen,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
  3822.                 break;
  3823.  
  3824.             case TRANSPARENCY_PENS:
  3825.                 if (pribuf)
  3826.                     BLOCKMOVE(8toN_transmask_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color,pribuf,pri_mask));
  3827.                 else
  3828.                     BLOCKMOVE(8toN_transmask,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
  3829.                 break;
  3830.  
  3831.             case TRANSPARENCY_COLOR:
  3832.                 if (pribuf)
  3833.                     BLOCKMOVE(8toN_transcolor_pri,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color,pribuf,pri_mask));
  3834.                 else
  3835.                     BLOCKMOVE(8toN_transcolor,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
  3836.                 break;
  3837.  
  3838.             case TRANSPARENCY_THROUGH:
  3839.                 if (pribuf)
  3840. usrintf_showmessage("pdrawgfx TRANS_THROUGH not supported");
  3841. //                    BLOCKMOVE(8toN_transthrough,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
  3842.                 else
  3843.                     BLOCKMOVE(8toN_transthrough,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
  3844.                 break;
  3845.  
  3846.             case TRANSPARENCY_PEN_TABLE:
  3847.                 if (pribuf)
  3848. usrintf_showmessage("pdrawgfx TRANS_PEN_TABLE not supported");
  3849. //                    BLOCKMOVE(8toN_pen_table,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
  3850.                 else
  3851.                     BLOCKMOVE(8toN_pen_table,flipx,(sd,sw,sh,sm,dd,dm,paldata,transparent_color));
  3852.                 break;
  3853.  
  3854.             case TRANSPARENCY_NONE_RAW:
  3855.                 if (pribuf)
  3856. usrintf_showmessage("pdrawgfx TRANS_NONE_RAW not supported");
  3857. //                    BLOCKMOVE(8toN_opaque_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
  3858.                 else
  3859.                     BLOCKMOVE(8toN_opaque_raw,flipx,(sd,sw,sh,sm,dd,dm,color));
  3860.                 break;
  3861.  
  3862.             case TRANSPARENCY_PEN_RAW:
  3863.                 if (pribuf)
  3864. usrintf_showmessage("pdrawgfx TRANS_PEN_RAW not supported");
  3865. //                    BLOCKMOVE(8toN_transpen_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
  3866.                 else
  3867.                     BLOCKMOVE(8toN_transpen_raw,flipx,(sd,sw,sh,sm,dd,dm,color,transparent_color));
  3868.                 break;
  3869.  
  3870.             case TRANSPARENCY_PENS_RAW:
  3871.                 if (pribuf)
  3872. usrintf_showmessage("pdrawgfx TRANS_PENS_RAW not supported");
  3873. //                    BLOCKMOVE(8toN_transmask_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
  3874.                 else
  3875.                     BLOCKMOVE(8toN_transmask_raw,flipx,(sd,sw,sh,sm,dd,dm,color,transparent_color));
  3876.                 break;
  3877.  
  3878.             case TRANSPARENCY_THROUGH_RAW:
  3879.                 if (pribuf)
  3880. usrintf_showmessage("pdrawgfx TRANS_PEN_RAW not supported");
  3881. //                    BLOCKMOVE(8toN_transpen_pri_raw,flipx,(sd,sw,sh,sm,dd,dm,paldata,pribuf,pri_mask));
  3882.                 else
  3883.                     BLOCKMOVE(8toN_transthrough_raw,flipx,(sd,sw,sh,sm,dd,dm,color,transparent_color));
  3884.                 break;
  3885.  
  3886.             default:
  3887.                 if (pribuf)
  3888.                     usrintf_showmessage("pdrawgfx pen mode not supported");
  3889.                 else
  3890.                     usrintf_showmessage("drawgfx pen mode not supported");
  3891.                 break;
  3892.         }
  3893.     }
  3894. })
  3895.  
  3896. DECLARE(copybitmap_core,(
  3897.         struct osd_bitmap *dest,struct osd_bitmap *src,
  3898.         int flipx,int flipy,int sx,int sy,
  3899.         const struct rectangle *clip,int transparency,int transparent_color),
  3900. {
  3901.     int ox;
  3902.     int oy;
  3903.     int ex;
  3904.     int ey;
  3905.  
  3906.  
  3907.     /* check bounds */
  3908.     ox = sx;
  3909.     oy = sy;
  3910.  
  3911.     ex = sx + src->width-1;
  3912.     if (sx < 0) sx = 0;
  3913.     if (clip && sx < clip->min_x) sx = clip->min_x;
  3914.     if (ex >= dest->width) ex = dest->width-1;
  3915.     if (clip && ex > clip->max_x) ex = clip->max_x;
  3916.     if (sx > ex) return;
  3917.  
  3918.     ey = sy + src->height-1;
  3919.     if (sy < 0) sy = 0;
  3920.     if (clip && sy < clip->min_y) sy = clip->min_y;
  3921.     if (ey >= dest->height) ey = dest->height-1;
  3922.     if (clip && ey > clip->max_y) ey = clip->max_y;
  3923.     if (sy > ey) return;
  3924.  
  3925.     {
  3926.         DATA_TYPE *sd = ((DATA_TYPE *)src->line[0]);                            /* source data */
  3927.         int sw = ex-sx+1;                                                        /* source width */
  3928.         int sh = ey-sy+1;                                                        /* source height */
  3929.         int sm = ((DATA_TYPE *)src->line[1])-((DATA_TYPE *)src->line[0]);        /* source modulo */
  3930.         DATA_TYPE *dd = ((DATA_TYPE *)dest->line[sy]) + sx;                        /* dest data */
  3931.         int dm = ((DATA_TYPE *)dest->line[1])-((DATA_TYPE *)dest->line[0]);        /* dest modulo */
  3932.  
  3933.         if (flipx)
  3934.         {
  3935.             //if ((sx-ox) == 0) sd += gfx->width - sw;
  3936.             sd += src->width -1 -(sx-ox);
  3937.         }
  3938.         else
  3939.             sd += (sx-ox);
  3940.  
  3941.         if (flipy)
  3942.         {
  3943.             //if ((sy-oy) == 0) sd += sm * (gfx->height - sh);
  3944.             //dd += dm * (sh - 1);
  3945.             //dm = -dm;
  3946.             sd += sm * (src->height -1 -(sy-oy));
  3947.             sm = -sm;
  3948.         }
  3949.         else
  3950.             sd += sm * (sy-oy);
  3951.  
  3952.         switch (transparency)
  3953.         {
  3954.             case TRANSPARENCY_NONE:
  3955.                 BLOCKMOVE(NtoN_opaque_remap,flipx,(sd,sw,sh,sm,dd,dm,Machine->pens));
  3956.                 break;
  3957.  
  3958.             case TRANSPARENCY_NONE_RAW:
  3959.                 BLOCKMOVE(NtoN_opaque_noremap,flipx,(sd,sw,sh,sm,dd,dm));
  3960.                 break;
  3961.  
  3962.             case TRANSPARENCY_PEN_RAW:
  3963.                 BLOCKMOVE(NtoN_transpen_noremap,flipx,(sd,sw,sh,sm,dd,dm,transparent_color));
  3964.                 break;
  3965.  
  3966.             case TRANSPARENCY_THROUGH_RAW:
  3967.                 BLOCKMOVE(NtoN_transthrough_noremap,flipx,(sd,sw,sh,sm,dd,dm,transparent_color));
  3968.                 break;
  3969.  
  3970.             case TRANSPARENCY_BLEND:
  3971.                 BLOCKMOVE(NtoN_blend_remap,flipx,(sd,sw,sh,sm,dd,dm,Machine->pens,transparent_color));
  3972.                 break;
  3973.  
  3974.             case TRANSPARENCY_BLEND_RAW:
  3975.                 BLOCKMOVE(NtoN_blend_noremap,flipx,(sd,sw,sh,sm,dd,dm,transparent_color));
  3976.                 break;
  3977.  
  3978.             default:
  3979.                 usrintf_showmessage("copybitmap pen mode not supported");
  3980.                 break;
  3981.         }
  3982.     }
  3983. })
  3984.  
  3985. #endif /* DECLARE */
  3986.